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_TSO
:
431 return sprintf(buf
, "%s\n", "TSO");
433 return sprintf(buf
, "%s\n", "N/A");
437 static ssize_t
qeth_dev_large_send_store(struct device
*dev
,
438 struct device_attribute
*attr
, const char *buf
, size_t count
)
440 struct qeth_card
*card
= dev_get_drvdata(dev
);
441 enum qeth_large_send_types type
;
447 tmp
= strsep((char **) &buf
, "\n");
448 if (!strcmp(tmp
, "no")) {
449 type
= QETH_LARGE_SEND_NO
;
450 } else if (!strcmp(tmp
, "TSO")) {
451 type
= QETH_LARGE_SEND_TSO
;
455 if (card
->options
.large_send
== type
)
457 rc
= qeth_set_large_send(card
, type
);
463 static DEVICE_ATTR(large_send
, 0644, qeth_dev_large_send_show
,
464 qeth_dev_large_send_store
);
466 static ssize_t
qeth_dev_blkt_show(char *buf
, struct qeth_card
*card
, int value
)
472 return sprintf(buf
, "%i\n", value
);
475 static ssize_t
qeth_dev_blkt_store(struct qeth_card
*card
,
476 const char *buf
, size_t count
, int *value
, int max_value
)
484 if ((card
->state
!= CARD_STATE_DOWN
) &&
485 (card
->state
!= CARD_STATE_RECOVER
))
488 i
= simple_strtoul(buf
, &tmp
, 10);
489 if (i
<= max_value
) {
497 static ssize_t
qeth_dev_blkt_total_show(struct device
*dev
,
498 struct device_attribute
*attr
, char *buf
)
500 struct qeth_card
*card
= dev_get_drvdata(dev
);
502 return qeth_dev_blkt_show(buf
, card
, card
->info
.blkt
.time_total
);
505 static ssize_t
qeth_dev_blkt_total_store(struct device
*dev
,
506 struct device_attribute
*attr
, const char *buf
, size_t count
)
508 struct qeth_card
*card
= dev_get_drvdata(dev
);
510 return qeth_dev_blkt_store(card
, buf
, count
,
511 &card
->info
.blkt
.time_total
, 1000);
516 static DEVICE_ATTR(total
, 0644, qeth_dev_blkt_total_show
,
517 qeth_dev_blkt_total_store
);
519 static ssize_t
qeth_dev_blkt_inter_show(struct device
*dev
,
520 struct device_attribute
*attr
, char *buf
)
522 struct qeth_card
*card
= dev_get_drvdata(dev
);
524 return qeth_dev_blkt_show(buf
, card
, card
->info
.blkt
.inter_packet
);
527 static ssize_t
qeth_dev_blkt_inter_store(struct device
*dev
,
528 struct device_attribute
*attr
, const char *buf
, size_t count
)
530 struct qeth_card
*card
= dev_get_drvdata(dev
);
532 return qeth_dev_blkt_store(card
, buf
, count
,
533 &card
->info
.blkt
.inter_packet
, 100);
536 static DEVICE_ATTR(inter
, 0644, qeth_dev_blkt_inter_show
,
537 qeth_dev_blkt_inter_store
);
539 static ssize_t
qeth_dev_blkt_inter_jumbo_show(struct device
*dev
,
540 struct device_attribute
*attr
, char *buf
)
542 struct qeth_card
*card
= dev_get_drvdata(dev
);
544 return qeth_dev_blkt_show(buf
, card
,
545 card
->info
.blkt
.inter_packet_jumbo
);
548 static ssize_t
qeth_dev_blkt_inter_jumbo_store(struct device
*dev
,
549 struct device_attribute
*attr
, const char *buf
, size_t count
)
551 struct qeth_card
*card
= dev_get_drvdata(dev
);
553 return qeth_dev_blkt_store(card
, buf
, count
,
554 &card
->info
.blkt
.inter_packet_jumbo
, 100);
557 static DEVICE_ATTR(inter_jumbo
, 0644, qeth_dev_blkt_inter_jumbo_show
,
558 qeth_dev_blkt_inter_jumbo_store
);
560 static struct attribute
*qeth_blkt_device_attrs
[] = {
561 &dev_attr_total
.attr
,
562 &dev_attr_inter
.attr
,
563 &dev_attr_inter_jumbo
.attr
,
567 static struct attribute_group qeth_device_blkt_group
= {
569 .attrs
= qeth_blkt_device_attrs
,
572 static struct attribute
*qeth_device_attrs
[] = {
573 &dev_attr_state
.attr
,
574 &dev_attr_chpid
.attr
,
575 &dev_attr_if_name
.attr
,
576 &dev_attr_card_type
.attr
,
577 &dev_attr_inbuf_size
.attr
,
578 &dev_attr_portno
.attr
,
579 &dev_attr_portname
.attr
,
580 &dev_attr_priority_queueing
.attr
,
581 &dev_attr_buffer_count
.attr
,
582 &dev_attr_recover
.attr
,
583 &dev_attr_performance_stats
.attr
,
584 &dev_attr_layer2
.attr
,
585 &dev_attr_large_send
.attr
,
589 static struct attribute_group qeth_device_attr_group
= {
590 .attrs
= qeth_device_attrs
,
593 static struct attribute
*qeth_osn_device_attrs
[] = {
594 &dev_attr_state
.attr
,
595 &dev_attr_chpid
.attr
,
596 &dev_attr_if_name
.attr
,
597 &dev_attr_card_type
.attr
,
598 &dev_attr_buffer_count
.attr
,
599 &dev_attr_recover
.attr
,
603 static struct attribute_group qeth_osn_device_attr_group
= {
604 .attrs
= qeth_osn_device_attrs
,
607 int qeth_core_create_device_attributes(struct device
*dev
)
610 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_attr_group
);
613 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_blkt_group
);
615 sysfs_remove_group(&dev
->kobj
, &qeth_device_attr_group
);
620 void qeth_core_remove_device_attributes(struct device
*dev
)
622 sysfs_remove_group(&dev
->kobj
, &qeth_device_attr_group
);
623 sysfs_remove_group(&dev
->kobj
, &qeth_device_blkt_group
);
626 int qeth_core_create_osn_attributes(struct device
*dev
)
628 return sysfs_create_group(&dev
->kobj
, &qeth_osn_device_attr_group
);
631 void qeth_core_remove_osn_attributes(struct device
*dev
)
633 sysfs_remove_group(&dev
->kobj
, &qeth_osn_device_attr_group
);