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
) {
132 PRINT_WARN("portno 0x%X is out of range\n", portno
);
136 card
->info
.portno
= portno
;
140 static DEVICE_ATTR(portno
, 0644, qeth_dev_portno_show
, qeth_dev_portno_store
);
142 static ssize_t
qeth_dev_portname_show(struct device
*dev
,
143 struct device_attribute
*attr
, char *buf
)
145 struct qeth_card
*card
= dev_get_drvdata(dev
);
146 char portname
[9] = {0, };
151 if (card
->info
.portname_required
) {
152 memcpy(portname
, card
->info
.portname
+ 1, 8);
154 return sprintf(buf
, "%s\n", portname
);
156 return sprintf(buf
, "no portname required\n");
159 static ssize_t
qeth_dev_portname_store(struct device
*dev
,
160 struct device_attribute
*attr
, const char *buf
, size_t count
)
162 struct qeth_card
*card
= dev_get_drvdata(dev
);
169 if ((card
->state
!= CARD_STATE_DOWN
) &&
170 (card
->state
!= CARD_STATE_RECOVER
))
173 tmp
= strsep((char **) &buf
, "\n");
174 if ((strlen(tmp
) > 8) || (strlen(tmp
) == 0))
177 card
->info
.portname
[0] = strlen(tmp
);
178 /* for beauty reasons */
179 for (i
= 1; i
< 9; i
++)
180 card
->info
.portname
[i
] = ' ';
181 strcpy(card
->info
.portname
+ 1, tmp
);
182 ASCEBC(card
->info
.portname
+ 1, 8);
187 static DEVICE_ATTR(portname
, 0644, qeth_dev_portname_show
,
188 qeth_dev_portname_store
);
190 static ssize_t
qeth_dev_prioqing_show(struct device
*dev
,
191 struct device_attribute
*attr
, char *buf
)
193 struct qeth_card
*card
= dev_get_drvdata(dev
);
198 switch (card
->qdio
.do_prio_queueing
) {
199 case QETH_PRIO_Q_ING_PREC
:
200 return sprintf(buf
, "%s\n", "by precedence");
201 case QETH_PRIO_Q_ING_TOS
:
202 return sprintf(buf
, "%s\n", "by type of service");
204 return sprintf(buf
, "always queue %i\n",
205 card
->qdio
.default_out_queue
);
209 static ssize_t
qeth_dev_prioqing_store(struct device
*dev
,
210 struct device_attribute
*attr
, const char *buf
, size_t count
)
212 struct qeth_card
*card
= dev_get_drvdata(dev
);
218 if ((card
->state
!= CARD_STATE_DOWN
) &&
219 (card
->state
!= CARD_STATE_RECOVER
))
222 /* check if 1920 devices are supported ,
223 * if though we have to permit priority queueing
225 if (card
->qdio
.no_out_queues
== 1) {
226 PRINT_WARN("Priority queueing disabled due "
227 "to hardware limitations!\n");
228 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
232 tmp
= strsep((char **) &buf
, "\n");
233 if (!strcmp(tmp
, "prio_queueing_prec"))
234 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_PREC
;
235 else if (!strcmp(tmp
, "prio_queueing_tos"))
236 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_TOS
;
237 else if (!strcmp(tmp
, "no_prio_queueing:0")) {
238 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
239 card
->qdio
.default_out_queue
= 0;
240 } else if (!strcmp(tmp
, "no_prio_queueing:1")) {
241 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
242 card
->qdio
.default_out_queue
= 1;
243 } else if (!strcmp(tmp
, "no_prio_queueing:2")) {
244 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
245 card
->qdio
.default_out_queue
= 2;
246 } else if (!strcmp(tmp
, "no_prio_queueing:3")) {
247 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
248 card
->qdio
.default_out_queue
= 3;
249 } else if (!strcmp(tmp
, "no_prio_queueing")) {
250 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
251 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
253 PRINT_WARN("Unknown queueing type '%s'\n", tmp
);
259 static DEVICE_ATTR(priority_queueing
, 0644, qeth_dev_prioqing_show
,
260 qeth_dev_prioqing_store
);
262 static ssize_t
qeth_dev_bufcnt_show(struct device
*dev
,
263 struct device_attribute
*attr
, char *buf
)
265 struct qeth_card
*card
= dev_get_drvdata(dev
);
270 return sprintf(buf
, "%i\n", card
->qdio
.in_buf_pool
.buf_count
);
273 static ssize_t
qeth_dev_bufcnt_store(struct device
*dev
,
274 struct device_attribute
*attr
, const char *buf
, size_t count
)
276 struct qeth_card
*card
= dev_get_drvdata(dev
);
284 if ((card
->state
!= CARD_STATE_DOWN
) &&
285 (card
->state
!= CARD_STATE_RECOVER
))
288 old_cnt
= card
->qdio
.in_buf_pool
.buf_count
;
289 cnt
= simple_strtoul(buf
, &tmp
, 10);
290 cnt
= (cnt
< QETH_IN_BUF_COUNT_MIN
) ? QETH_IN_BUF_COUNT_MIN
:
291 ((cnt
> QETH_IN_BUF_COUNT_MAX
) ? QETH_IN_BUF_COUNT_MAX
: cnt
);
292 if (old_cnt
!= cnt
) {
293 rc
= qeth_realloc_buffer_pool(card
, cnt
);
295 PRINT_WARN("Error (%d) while setting "
296 "buffer count.\n", rc
);
301 static DEVICE_ATTR(buffer_count
, 0644, qeth_dev_bufcnt_show
,
302 qeth_dev_bufcnt_store
);
304 static ssize_t
qeth_dev_recover_store(struct device
*dev
,
305 struct device_attribute
*attr
, const char *buf
, size_t count
)
307 struct qeth_card
*card
= dev_get_drvdata(dev
);
314 if (card
->state
!= CARD_STATE_UP
)
317 i
= simple_strtoul(buf
, &tmp
, 16);
319 qeth_schedule_recovery(card
);
324 static DEVICE_ATTR(recover
, 0200, NULL
, qeth_dev_recover_store
);
326 static ssize_t
qeth_dev_performance_stats_show(struct device
*dev
,
327 struct device_attribute
*attr
, char *buf
)
329 struct qeth_card
*card
= dev_get_drvdata(dev
);
334 return sprintf(buf
, "%i\n", card
->options
.performance_stats
? 1:0);
337 static ssize_t
qeth_dev_performance_stats_store(struct device
*dev
,
338 struct device_attribute
*attr
, const char *buf
, size_t count
)
340 struct qeth_card
*card
= dev_get_drvdata(dev
);
347 i
= simple_strtoul(buf
, &tmp
, 16);
348 if ((i
== 0) || (i
== 1)) {
349 if (i
== card
->options
.performance_stats
)
351 card
->options
.performance_stats
= i
;
353 memset(&card
->perf_stats
, 0,
354 sizeof(struct qeth_perf_stats
));
355 card
->perf_stats
.initial_rx_packets
= card
->stats
.rx_packets
;
356 card
->perf_stats
.initial_tx_packets
= card
->stats
.tx_packets
;
358 PRINT_WARN("performance_stats: write 0 or 1 to this file!\n");
364 static DEVICE_ATTR(performance_stats
, 0644, qeth_dev_performance_stats_show
,
365 qeth_dev_performance_stats_store
);
367 static ssize_t
qeth_dev_layer2_show(struct device
*dev
,
368 struct device_attribute
*attr
, char *buf
)
370 struct qeth_card
*card
= dev_get_drvdata(dev
);
375 return sprintf(buf
, "%i\n", card
->options
.layer2
? 1:0);
378 static ssize_t
qeth_dev_layer2_store(struct device
*dev
,
379 struct device_attribute
*attr
, const char *buf
, size_t count
)
381 struct qeth_card
*card
= dev_get_drvdata(dev
);
384 enum qeth_discipline_id newdis
;
389 if (((card
->state
!= CARD_STATE_DOWN
) &&
390 (card
->state
!= CARD_STATE_RECOVER
)))
393 i
= simple_strtoul(buf
, &tmp
, 16);
396 newdis
= QETH_DISCIPLINE_LAYER3
;
399 newdis
= QETH_DISCIPLINE_LAYER2
;
402 PRINT_WARN("layer2: write 0 or 1 to this file!\n");
406 if (card
->options
.layer2
== newdis
) {
409 if (card
->discipline
.ccwgdriver
) {
410 card
->discipline
.ccwgdriver
->remove(card
->gdev
);
411 qeth_core_free_discipline(card
);
415 rc
= qeth_core_load_discipline(card
, newdis
);
419 rc
= card
->discipline
.ccwgdriver
->probe(card
->gdev
);
425 static DEVICE_ATTR(layer2
, 0644, qeth_dev_layer2_show
,
426 qeth_dev_layer2_store
);
428 static ssize_t
qeth_dev_large_send_show(struct device
*dev
,
429 struct device_attribute
*attr
, char *buf
)
431 struct qeth_card
*card
= dev_get_drvdata(dev
);
436 switch (card
->options
.large_send
) {
437 case QETH_LARGE_SEND_NO
:
438 return sprintf(buf
, "%s\n", "no");
439 case QETH_LARGE_SEND_EDDP
:
440 return sprintf(buf
, "%s\n", "EDDP");
441 case QETH_LARGE_SEND_TSO
:
442 return sprintf(buf
, "%s\n", "TSO");
444 return sprintf(buf
, "%s\n", "N/A");
448 static ssize_t
qeth_dev_large_send_store(struct device
*dev
,
449 struct device_attribute
*attr
, const char *buf
, size_t count
)
451 struct qeth_card
*card
= dev_get_drvdata(dev
);
452 enum qeth_large_send_types type
;
458 tmp
= strsep((char **) &buf
, "\n");
459 if (!strcmp(tmp
, "no")) {
460 type
= QETH_LARGE_SEND_NO
;
461 } else if (!strcmp(tmp
, "EDDP")) {
462 type
= QETH_LARGE_SEND_EDDP
;
463 } else if (!strcmp(tmp
, "TSO")) {
464 type
= QETH_LARGE_SEND_TSO
;
466 PRINT_WARN("large_send: invalid mode %s!\n", tmp
);
469 if (card
->options
.large_send
== type
)
471 rc
= qeth_set_large_send(card
, type
);
477 static DEVICE_ATTR(large_send
, 0644, qeth_dev_large_send_show
,
478 qeth_dev_large_send_store
);
480 static ssize_t
qeth_dev_blkt_show(char *buf
, struct qeth_card
*card
, int value
)
486 return sprintf(buf
, "%i\n", value
);
489 static ssize_t
qeth_dev_blkt_store(struct qeth_card
*card
,
490 const char *buf
, size_t count
, int *value
, int max_value
)
498 if ((card
->state
!= CARD_STATE_DOWN
) &&
499 (card
->state
!= CARD_STATE_RECOVER
))
502 i
= simple_strtoul(buf
, &tmp
, 10);
503 if (i
<= max_value
) {
506 PRINT_WARN("blkt total time: write values between"
507 " 0 and %d to this file!\n", max_value
);
513 static ssize_t
qeth_dev_blkt_total_show(struct device
*dev
,
514 struct device_attribute
*attr
, char *buf
)
516 struct qeth_card
*card
= dev_get_drvdata(dev
);
518 return qeth_dev_blkt_show(buf
, card
, card
->info
.blkt
.time_total
);
521 static ssize_t
qeth_dev_blkt_total_store(struct device
*dev
,
522 struct device_attribute
*attr
, const char *buf
, size_t count
)
524 struct qeth_card
*card
= dev_get_drvdata(dev
);
526 return qeth_dev_blkt_store(card
, buf
, count
,
527 &card
->info
.blkt
.time_total
, 1000);
532 static DEVICE_ATTR(total
, 0644, qeth_dev_blkt_total_show
,
533 qeth_dev_blkt_total_store
);
535 static ssize_t
qeth_dev_blkt_inter_show(struct device
*dev
,
536 struct device_attribute
*attr
, char *buf
)
538 struct qeth_card
*card
= dev_get_drvdata(dev
);
540 return qeth_dev_blkt_show(buf
, card
, card
->info
.blkt
.inter_packet
);
543 static ssize_t
qeth_dev_blkt_inter_store(struct device
*dev
,
544 struct device_attribute
*attr
, const char *buf
, size_t count
)
546 struct qeth_card
*card
= dev_get_drvdata(dev
);
548 return qeth_dev_blkt_store(card
, buf
, count
,
549 &card
->info
.blkt
.inter_packet
, 100);
552 static DEVICE_ATTR(inter
, 0644, qeth_dev_blkt_inter_show
,
553 qeth_dev_blkt_inter_store
);
555 static ssize_t
qeth_dev_blkt_inter_jumbo_show(struct device
*dev
,
556 struct device_attribute
*attr
, char *buf
)
558 struct qeth_card
*card
= dev_get_drvdata(dev
);
560 return qeth_dev_blkt_show(buf
, card
,
561 card
->info
.blkt
.inter_packet_jumbo
);
564 static ssize_t
qeth_dev_blkt_inter_jumbo_store(struct device
*dev
,
565 struct device_attribute
*attr
, const char *buf
, size_t count
)
567 struct qeth_card
*card
= dev_get_drvdata(dev
);
569 return qeth_dev_blkt_store(card
, buf
, count
,
570 &card
->info
.blkt
.inter_packet_jumbo
, 100);
573 static DEVICE_ATTR(inter_jumbo
, 0644, qeth_dev_blkt_inter_jumbo_show
,
574 qeth_dev_blkt_inter_jumbo_store
);
576 static struct attribute
*qeth_blkt_device_attrs
[] = {
577 &dev_attr_total
.attr
,
578 &dev_attr_inter
.attr
,
579 &dev_attr_inter_jumbo
.attr
,
583 static struct attribute_group qeth_device_blkt_group
= {
585 .attrs
= qeth_blkt_device_attrs
,
588 static struct attribute
*qeth_device_attrs
[] = {
589 &dev_attr_state
.attr
,
590 &dev_attr_chpid
.attr
,
591 &dev_attr_if_name
.attr
,
592 &dev_attr_card_type
.attr
,
593 &dev_attr_inbuf_size
.attr
,
594 &dev_attr_portno
.attr
,
595 &dev_attr_portname
.attr
,
596 &dev_attr_priority_queueing
.attr
,
597 &dev_attr_buffer_count
.attr
,
598 &dev_attr_recover
.attr
,
599 &dev_attr_performance_stats
.attr
,
600 &dev_attr_layer2
.attr
,
601 &dev_attr_large_send
.attr
,
605 static struct attribute_group qeth_device_attr_group
= {
606 .attrs
= qeth_device_attrs
,
609 static struct attribute
*qeth_osn_device_attrs
[] = {
610 &dev_attr_state
.attr
,
611 &dev_attr_chpid
.attr
,
612 &dev_attr_if_name
.attr
,
613 &dev_attr_card_type
.attr
,
614 &dev_attr_buffer_count
.attr
,
615 &dev_attr_recover
.attr
,
619 static struct attribute_group qeth_osn_device_attr_group
= {
620 .attrs
= qeth_osn_device_attrs
,
623 int qeth_core_create_device_attributes(struct device
*dev
)
626 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_attr_group
);
629 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_blkt_group
);
631 sysfs_remove_group(&dev
->kobj
, &qeth_device_attr_group
);
636 void qeth_core_remove_device_attributes(struct device
*dev
)
638 sysfs_remove_group(&dev
->kobj
, &qeth_device_attr_group
);
639 sysfs_remove_group(&dev
->kobj
, &qeth_device_blkt_group
);
642 int qeth_core_create_osn_attributes(struct device
*dev
)
644 return sysfs_create_group(&dev
->kobj
, &qeth_osn_device_attr_group
);
647 void qeth_core_remove_osn_attributes(struct device
*dev
)
649 sysfs_remove_group(&dev
->kobj
, &qeth_osn_device_attr_group
);