2 * drivers/s390/net/qeth_core_sys.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
11 #include <linux/list.h>
12 #include <linux/rwsem.h>
13 #include <asm/ebcdic.h>
15 #include "qeth_core.h"
17 static ssize_t qeth_dev_state_show(struct device *dev,
18 struct device_attribute *attr, char *buf)
20 struct qeth_card *card = dev_get_drvdata(dev);
24 switch (card->state) {
26 return sprintf(buf, "DOWN\n");
27 case CARD_STATE_HARDSETUP:
28 return sprintf(buf, "HARDSETUP\n");
29 case CARD_STATE_SOFTSETUP:
30 return sprintf(buf, "SOFTSETUP\n");
33 return sprintf(buf, "UP (LAN ONLINE)\n");
35 return sprintf(buf, "UP (LAN OFFLINE)\n");
36 case CARD_STATE_RECOVER:
37 return sprintf(buf, "RECOVER\n");
39 return sprintf(buf, "UNKNOWN\n");
43 static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
45 static ssize_t qeth_dev_chpid_show(struct device *dev,
46 struct device_attribute *attr, char *buf)
48 struct qeth_card *card = dev_get_drvdata(dev);
52 return sprintf(buf, "%02X\n", card->info.chpid);
55 static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
57 static ssize_t qeth_dev_if_name_show(struct device *dev,
58 struct device_attribute *attr, char *buf)
60 struct qeth_card *card = dev_get_drvdata(dev);
63 return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
66 static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
68 static ssize_t qeth_dev_card_type_show(struct device *dev,
69 struct device_attribute *attr, char *buf)
71 struct qeth_card *card = dev_get_drvdata(dev);
75 return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
78 static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
80 static inline const char *qeth_get_bufsize_str(struct qeth_card *card)
82 if (card->qdio.in_buf_size == 16384)
84 else if (card->qdio.in_buf_size == 24576)
86 else if (card->qdio.in_buf_size == 32768)
88 else if (card->qdio.in_buf_size == 40960)
94 static ssize_t qeth_dev_inbuf_size_show(struct device *dev,
95 struct device_attribute *attr, char *buf)
97 struct qeth_card *card = dev_get_drvdata(dev);
101 return sprintf(buf, "%s\n", qeth_get_bufsize_str(card));
104 static DEVICE_ATTR(inbuf_size, 0444, qeth_dev_inbuf_size_show, NULL);
106 static ssize_t qeth_dev_portno_show(struct device *dev,
107 struct device_attribute *attr, char *buf)
109 struct qeth_card *card = dev_get_drvdata(dev);
113 return sprintf(buf, "%i\n", card->info.portno);
116 static ssize_t qeth_dev_portno_store(struct device *dev,
117 struct device_attribute *attr, const char *buf, size_t count)
119 struct qeth_card *card = dev_get_drvdata(dev);
126 if ((card->state != CARD_STATE_DOWN) &&
127 (card->state != CARD_STATE_RECOVER))
130 portno = simple_strtoul(buf, &tmp, 16);
131 if (portno > QETH_MAX_PORTNO) {
135 card->info.portno = portno;
139 static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
141 static ssize_t qeth_dev_portname_show(struct device *dev,
142 struct device_attribute *attr, char *buf)
144 struct qeth_card *card = dev_get_drvdata(dev);
145 char portname[9] = {0, };
150 if (card->info.portname_required) {
151 memcpy(portname, card->info.portname + 1, 8);
153 return sprintf(buf, "%s\n", portname);
155 return sprintf(buf, "no portname required\n");
158 static ssize_t qeth_dev_portname_store(struct device *dev,
159 struct device_attribute *attr, const char *buf, size_t count)
161 struct qeth_card *card = dev_get_drvdata(dev);
168 if ((card->state != CARD_STATE_DOWN) &&
169 (card->state != CARD_STATE_RECOVER))
172 tmp = strsep((char **) &buf, "\n");
173 if ((strlen(tmp) > 8) || (strlen(tmp) == 0))
176 card->info.portname[0] = strlen(tmp);
177 /* for beauty reasons */
178 for (i = 1; i < 9; i++)
179 card->info.portname[i] = ' ';
180 strcpy(card->info.portname + 1, tmp);
181 ASCEBC(card->info.portname + 1, 8);
186 static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
187 qeth_dev_portname_store);
189 static ssize_t qeth_dev_prioqing_show(struct device *dev,
190 struct device_attribute *attr, char *buf)
192 struct qeth_card *card = dev_get_drvdata(dev);
197 switch (card->qdio.do_prio_queueing) {
198 case QETH_PRIO_Q_ING_PREC:
199 return sprintf(buf, "%s\n", "by precedence");
200 case QETH_PRIO_Q_ING_TOS:
201 return sprintf(buf, "%s\n", "by type of service");
203 return sprintf(buf, "always queue %i\n",
204 card->qdio.default_out_queue);
208 static ssize_t qeth_dev_prioqing_store(struct device *dev,
209 struct device_attribute *attr, const char *buf, size_t count)
211 struct qeth_card *card = dev_get_drvdata(dev);
217 if ((card->state != CARD_STATE_DOWN) &&
218 (card->state != CARD_STATE_RECOVER))
221 /* check if 1920 devices are supported ,
222 * if though we have to permit priority queueing
224 if (card->qdio.no_out_queues == 1) {
225 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
229 tmp = strsep((char **) &buf, "\n");
230 if (!strcmp(tmp, "prio_queueing_prec"))
231 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
232 else if (!strcmp(tmp, "prio_queueing_tos"))
233 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
234 else if (!strcmp(tmp, "no_prio_queueing:0")) {
235 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
236 card->qdio.default_out_queue = 0;
237 } else if (!strcmp(tmp, "no_prio_queueing:1")) {
238 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
239 card->qdio.default_out_queue = 1;
240 } else if (!strcmp(tmp, "no_prio_queueing:2")) {
241 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
242 card->qdio.default_out_queue = 2;
243 } else if (!strcmp(tmp, "no_prio_queueing:3")) {
244 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
245 card->qdio.default_out_queue = 3;
246 } else if (!strcmp(tmp, "no_prio_queueing")) {
247 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
248 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
255 static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
256 qeth_dev_prioqing_store);
258 static ssize_t qeth_dev_bufcnt_show(struct device *dev,
259 struct device_attribute *attr, char *buf)
261 struct qeth_card *card = dev_get_drvdata(dev);
266 return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
269 static ssize_t qeth_dev_bufcnt_store(struct device *dev,
270 struct device_attribute *attr, const char *buf, size_t count)
272 struct qeth_card *card = dev_get_drvdata(dev);
280 if ((card->state != CARD_STATE_DOWN) &&
281 (card->state != CARD_STATE_RECOVER))
284 old_cnt = card->qdio.in_buf_pool.buf_count;
285 cnt = simple_strtoul(buf, &tmp, 10);
286 cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
287 ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
288 if (old_cnt != cnt) {
289 rc = qeth_realloc_buffer_pool(card, cnt);
294 static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
295 qeth_dev_bufcnt_store);
297 static ssize_t qeth_dev_recover_store(struct device *dev,
298 struct device_attribute *attr, const char *buf, size_t count)
300 struct qeth_card *card = dev_get_drvdata(dev);
307 if (card->state != CARD_STATE_UP)
310 i = simple_strtoul(buf, &tmp, 16);
312 qeth_schedule_recovery(card);
317 static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
319 static ssize_t qeth_dev_performance_stats_show(struct device *dev,
320 struct device_attribute *attr, char *buf)
322 struct qeth_card *card = dev_get_drvdata(dev);
327 return sprintf(buf, "%i\n", card->options.performance_stats ? 1:0);
330 static ssize_t qeth_dev_performance_stats_store(struct device *dev,
331 struct device_attribute *attr, const char *buf, size_t count)
333 struct qeth_card *card = dev_get_drvdata(dev);
340 i = simple_strtoul(buf, &tmp, 16);
341 if ((i == 0) || (i == 1)) {
342 if (i == card->options.performance_stats)
344 card->options.performance_stats = i;
346 memset(&card->perf_stats, 0,
347 sizeof(struct qeth_perf_stats));
348 card->perf_stats.initial_rx_packets = card->stats.rx_packets;
349 card->perf_stats.initial_tx_packets = card->stats.tx_packets;
356 static DEVICE_ATTR(performance_stats, 0644, qeth_dev_performance_stats_show,
357 qeth_dev_performance_stats_store);
359 static ssize_t qeth_dev_layer2_show(struct device *dev,
360 struct device_attribute *attr, char *buf)
362 struct qeth_card *card = dev_get_drvdata(dev);
367 return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
370 static ssize_t qeth_dev_layer2_store(struct device *dev,
371 struct device_attribute *attr, const char *buf, size_t count)
373 struct qeth_card *card = dev_get_drvdata(dev);
376 enum qeth_discipline_id newdis;
381 if (((card->state != CARD_STATE_DOWN) &&
382 (card->state != CARD_STATE_RECOVER)))
385 i = simple_strtoul(buf, &tmp, 16);
388 newdis = QETH_DISCIPLINE_LAYER3;
391 newdis = QETH_DISCIPLINE_LAYER2;
397 if (card->options.layer2 == newdis) {
400 if (card->discipline.ccwgdriver) {
401 card->discipline.ccwgdriver->remove(card->gdev);
402 qeth_core_free_discipline(card);
406 rc = qeth_core_load_discipline(card, newdis);
410 rc = card->discipline.ccwgdriver->probe(card->gdev);
416 static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
417 qeth_dev_layer2_store);
419 static ssize_t qeth_dev_large_send_show(struct device *dev,
420 struct device_attribute *attr, char *buf)
422 struct qeth_card *card = dev_get_drvdata(dev);
427 switch (card->options.large_send) {
428 case QETH_LARGE_SEND_NO:
429 return sprintf(buf, "%s\n", "no");
430 case QETH_LARGE_SEND_EDDP:
431 return sprintf(buf, "%s\n", "EDDP");
432 case QETH_LARGE_SEND_TSO:
433 return sprintf(buf, "%s\n", "TSO");
435 return sprintf(buf, "%s\n", "N/A");
439 static ssize_t qeth_dev_large_send_store(struct device *dev,
440 struct device_attribute *attr, const char *buf, size_t count)
442 struct qeth_card *card = dev_get_drvdata(dev);
443 enum qeth_large_send_types type;
449 tmp = strsep((char **) &buf, "\n");
450 if (!strcmp(tmp, "no")) {
451 type = QETH_LARGE_SEND_NO;
452 } else if (!strcmp(tmp, "EDDP")) {
453 type = QETH_LARGE_SEND_EDDP;
454 } else if (!strcmp(tmp, "TSO")) {
455 type = QETH_LARGE_SEND_TSO;
459 if (card->options.large_send == type)
461 rc = qeth_set_large_send(card, type);
467 static DEVICE_ATTR(large_send, 0644, qeth_dev_large_send_show,
468 qeth_dev_large_send_store);
470 static ssize_t qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value)
476 return sprintf(buf, "%i\n", value);
479 static ssize_t qeth_dev_blkt_store(struct qeth_card *card,
480 const char *buf, size_t count, int *value, int max_value)
488 if ((card->state != CARD_STATE_DOWN) &&
489 (card->state != CARD_STATE_RECOVER))
492 i = simple_strtoul(buf, &tmp, 10);
493 if (i <= max_value) {
501 static ssize_t qeth_dev_blkt_total_show(struct device *dev,
502 struct device_attribute *attr, char *buf)
504 struct qeth_card *card = dev_get_drvdata(dev);
506 return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
509 static ssize_t qeth_dev_blkt_total_store(struct device *dev,
510 struct device_attribute *attr, const char *buf, size_t count)
512 struct qeth_card *card = dev_get_drvdata(dev);
514 return qeth_dev_blkt_store(card, buf, count,
515 &card->info.blkt.time_total, 1000);
520 static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
521 qeth_dev_blkt_total_store);
523 static ssize_t qeth_dev_blkt_inter_show(struct device *dev,
524 struct device_attribute *attr, char *buf)
526 struct qeth_card *card = dev_get_drvdata(dev);
528 return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
531 static ssize_t qeth_dev_blkt_inter_store(struct device *dev,
532 struct device_attribute *attr, const char *buf, size_t count)
534 struct qeth_card *card = dev_get_drvdata(dev);
536 return qeth_dev_blkt_store(card, buf, count,
537 &card->info.blkt.inter_packet, 100);
540 static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
541 qeth_dev_blkt_inter_store);
543 static ssize_t qeth_dev_blkt_inter_jumbo_show(struct device *dev,
544 struct device_attribute *attr, char *buf)
546 struct qeth_card *card = dev_get_drvdata(dev);
548 return qeth_dev_blkt_show(buf, card,
549 card->info.blkt.inter_packet_jumbo);
552 static ssize_t qeth_dev_blkt_inter_jumbo_store(struct device *dev,
553 struct device_attribute *attr, const char *buf, size_t count)
555 struct qeth_card *card = dev_get_drvdata(dev);
557 return qeth_dev_blkt_store(card, buf, count,
558 &card->info.blkt.inter_packet_jumbo, 100);
561 static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
562 qeth_dev_blkt_inter_jumbo_store);
564 static struct attribute *qeth_blkt_device_attrs[] = {
565 &dev_attr_total.attr,
566 &dev_attr_inter.attr,
567 &dev_attr_inter_jumbo.attr,
571 static struct attribute_group qeth_device_blkt_group = {
573 .attrs = qeth_blkt_device_attrs,
576 static struct attribute *qeth_device_attrs[] = {
577 &dev_attr_state.attr,
578 &dev_attr_chpid.attr,
579 &dev_attr_if_name.attr,
580 &dev_attr_card_type.attr,
581 &dev_attr_inbuf_size.attr,
582 &dev_attr_portno.attr,
583 &dev_attr_portname.attr,
584 &dev_attr_priority_queueing.attr,
585 &dev_attr_buffer_count.attr,
586 &dev_attr_recover.attr,
587 &dev_attr_performance_stats.attr,
588 &dev_attr_layer2.attr,
589 &dev_attr_large_send.attr,
593 static struct attribute_group qeth_device_attr_group = {
594 .attrs = qeth_device_attrs,
597 static struct attribute *qeth_osn_device_attrs[] = {
598 &dev_attr_state.attr,
599 &dev_attr_chpid.attr,
600 &dev_attr_if_name.attr,
601 &dev_attr_card_type.attr,
602 &dev_attr_buffer_count.attr,
603 &dev_attr_recover.attr,
607 static struct attribute_group qeth_osn_device_attr_group = {
608 .attrs = qeth_osn_device_attrs,
611 int qeth_core_create_device_attributes(struct device *dev)
614 ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group);
617 ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group);
619 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
624 void qeth_core_remove_device_attributes(struct device *dev)
626 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
627 sysfs_remove_group(&dev->kobj, &qeth_device_blkt_group);
630 int qeth_core_create_osn_attributes(struct device *dev)
632 return sysfs_create_group(&dev->kobj, &qeth_osn_device_attr_group);
635 void qeth_core_remove_osn_attributes(struct device *dev)
637 sysfs_remove_group(&dev->kobj, &qeth_osn_device_attr_group);