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 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/list.h>
15 #include <linux/rwsem.h>
16 #include <asm/ebcdic.h>
18 #include "qeth_core.h"
20 static ssize_t
qeth_dev_state_show(struct device
*dev
,
21 struct device_attribute
*attr
, char *buf
)
23 struct qeth_card
*card
= dev_get_drvdata(dev
);
27 switch (card
->state
) {
29 return sprintf(buf
, "DOWN\n");
30 case CARD_STATE_HARDSETUP
:
31 return sprintf(buf
, "HARDSETUP\n");
32 case CARD_STATE_SOFTSETUP
:
33 return sprintf(buf
, "SOFTSETUP\n");
36 return sprintf(buf
, "UP (LAN ONLINE)\n");
38 return sprintf(buf
, "UP (LAN OFFLINE)\n");
39 case CARD_STATE_RECOVER
:
40 return sprintf(buf
, "RECOVER\n");
42 return sprintf(buf
, "UNKNOWN\n");
46 static DEVICE_ATTR(state
, 0444, qeth_dev_state_show
, NULL
);
48 static ssize_t
qeth_dev_chpid_show(struct device
*dev
,
49 struct device_attribute
*attr
, char *buf
)
51 struct qeth_card
*card
= dev_get_drvdata(dev
);
55 return sprintf(buf
, "%02X\n", card
->info
.chpid
);
58 static DEVICE_ATTR(chpid
, 0444, qeth_dev_chpid_show
, NULL
);
60 static ssize_t
qeth_dev_if_name_show(struct device
*dev
,
61 struct device_attribute
*attr
, char *buf
)
63 struct qeth_card
*card
= dev_get_drvdata(dev
);
66 return sprintf(buf
, "%s\n", QETH_CARD_IFNAME(card
));
69 static DEVICE_ATTR(if_name
, 0444, qeth_dev_if_name_show
, NULL
);
71 static ssize_t
qeth_dev_card_type_show(struct device
*dev
,
72 struct device_attribute
*attr
, char *buf
)
74 struct qeth_card
*card
= dev_get_drvdata(dev
);
78 return sprintf(buf
, "%s\n", qeth_get_cardname_short(card
));
81 static DEVICE_ATTR(card_type
, 0444, qeth_dev_card_type_show
, NULL
);
83 static inline const char *qeth_get_bufsize_str(struct qeth_card
*card
)
85 if (card
->qdio
.in_buf_size
== 16384)
87 else if (card
->qdio
.in_buf_size
== 24576)
89 else if (card
->qdio
.in_buf_size
== 32768)
91 else if (card
->qdio
.in_buf_size
== 40960)
97 static ssize_t
qeth_dev_inbuf_size_show(struct device
*dev
,
98 struct device_attribute
*attr
, char *buf
)
100 struct qeth_card
*card
= dev_get_drvdata(dev
);
104 return sprintf(buf
, "%s\n", qeth_get_bufsize_str(card
));
107 static DEVICE_ATTR(inbuf_size
, 0444, qeth_dev_inbuf_size_show
, NULL
);
109 static ssize_t
qeth_dev_portno_show(struct device
*dev
,
110 struct device_attribute
*attr
, char *buf
)
112 struct qeth_card
*card
= dev_get_drvdata(dev
);
116 return sprintf(buf
, "%i\n", card
->info
.portno
);
119 static ssize_t
qeth_dev_portno_store(struct device
*dev
,
120 struct device_attribute
*attr
, const char *buf
, size_t count
)
122 struct qeth_card
*card
= dev_get_drvdata(dev
);
124 unsigned int portno
, limit
;
130 mutex_lock(&card
->conf_mutex
);
131 if ((card
->state
!= CARD_STATE_DOWN
) &&
132 (card
->state
!= CARD_STATE_RECOVER
)) {
137 portno
= simple_strtoul(buf
, &tmp
, 16);
138 if (portno
> QETH_MAX_PORTNO
) {
142 limit
= (card
->ssqd
.pcnt
? card
->ssqd
.pcnt
- 1 : card
->ssqd
.pcnt
);
143 if (portno
> limit
) {
147 card
->info
.portno
= portno
;
149 mutex_unlock(&card
->conf_mutex
);
150 return rc
? rc
: count
;
153 static DEVICE_ATTR(portno
, 0644, qeth_dev_portno_show
, qeth_dev_portno_store
);
155 static ssize_t
qeth_dev_portname_show(struct device
*dev
,
156 struct device_attribute
*attr
, char *buf
)
158 struct qeth_card
*card
= dev_get_drvdata(dev
);
159 char portname
[9] = {0, };
164 if (card
->info
.portname_required
) {
165 memcpy(portname
, card
->info
.portname
+ 1, 8);
167 return sprintf(buf
, "%s\n", portname
);
169 return sprintf(buf
, "no portname required\n");
172 static ssize_t
qeth_dev_portname_store(struct device
*dev
,
173 struct device_attribute
*attr
, const char *buf
, size_t count
)
175 struct qeth_card
*card
= dev_get_drvdata(dev
);
182 mutex_lock(&card
->conf_mutex
);
183 if ((card
->state
!= CARD_STATE_DOWN
) &&
184 (card
->state
!= CARD_STATE_RECOVER
)) {
189 tmp
= strsep((char **) &buf
, "\n");
190 if ((strlen(tmp
) > 8) || (strlen(tmp
) == 0)) {
195 card
->info
.portname
[0] = strlen(tmp
);
196 /* for beauty reasons */
197 for (i
= 1; i
< 9; i
++)
198 card
->info
.portname
[i
] = ' ';
199 strcpy(card
->info
.portname
+ 1, tmp
);
200 ASCEBC(card
->info
.portname
+ 1, 8);
202 mutex_unlock(&card
->conf_mutex
);
203 return rc
? rc
: count
;
206 static DEVICE_ATTR(portname
, 0644, qeth_dev_portname_show
,
207 qeth_dev_portname_store
);
209 static ssize_t
qeth_dev_prioqing_show(struct device
*dev
,
210 struct device_attribute
*attr
, char *buf
)
212 struct qeth_card
*card
= dev_get_drvdata(dev
);
217 switch (card
->qdio
.do_prio_queueing
) {
218 case QETH_PRIO_Q_ING_PREC
:
219 return sprintf(buf
, "%s\n", "by precedence");
220 case QETH_PRIO_Q_ING_TOS
:
221 return sprintf(buf
, "%s\n", "by type of service");
223 return sprintf(buf
, "always queue %i\n",
224 card
->qdio
.default_out_queue
);
228 static ssize_t
qeth_dev_prioqing_store(struct device
*dev
,
229 struct device_attribute
*attr
, const char *buf
, size_t count
)
231 struct qeth_card
*card
= dev_get_drvdata(dev
);
238 mutex_lock(&card
->conf_mutex
);
239 if ((card
->state
!= CARD_STATE_DOWN
) &&
240 (card
->state
!= CARD_STATE_RECOVER
)) {
245 /* check if 1920 devices are supported ,
246 * if though we have to permit priority queueing
248 if (card
->qdio
.no_out_queues
== 1) {
249 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
254 tmp
= strsep((char **) &buf
, "\n");
255 if (!strcmp(tmp
, "prio_queueing_prec"))
256 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_PREC
;
257 else if (!strcmp(tmp
, "prio_queueing_tos"))
258 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_TOS
;
259 else if (!strcmp(tmp
, "no_prio_queueing:0")) {
260 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
261 card
->qdio
.default_out_queue
= 0;
262 } else if (!strcmp(tmp
, "no_prio_queueing:1")) {
263 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
264 card
->qdio
.default_out_queue
= 1;
265 } else if (!strcmp(tmp
, "no_prio_queueing:2")) {
266 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
267 card
->qdio
.default_out_queue
= 2;
268 } else if (!strcmp(tmp
, "no_prio_queueing:3")) {
269 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
270 card
->qdio
.default_out_queue
= 3;
271 } else if (!strcmp(tmp
, "no_prio_queueing")) {
272 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
273 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
277 mutex_unlock(&card
->conf_mutex
);
278 return rc
? rc
: count
;
281 static DEVICE_ATTR(priority_queueing
, 0644, qeth_dev_prioqing_show
,
282 qeth_dev_prioqing_store
);
284 static ssize_t
qeth_dev_bufcnt_show(struct device
*dev
,
285 struct device_attribute
*attr
, char *buf
)
287 struct qeth_card
*card
= dev_get_drvdata(dev
);
292 return sprintf(buf
, "%i\n", card
->qdio
.in_buf_pool
.buf_count
);
295 static ssize_t
qeth_dev_bufcnt_store(struct device
*dev
,
296 struct device_attribute
*attr
, const char *buf
, size_t count
)
298 struct qeth_card
*card
= dev_get_drvdata(dev
);
306 mutex_lock(&card
->conf_mutex
);
307 if ((card
->state
!= CARD_STATE_DOWN
) &&
308 (card
->state
!= CARD_STATE_RECOVER
)) {
313 old_cnt
= card
->qdio
.in_buf_pool
.buf_count
;
314 cnt
= simple_strtoul(buf
, &tmp
, 10);
315 cnt
= (cnt
< QETH_IN_BUF_COUNT_MIN
) ? QETH_IN_BUF_COUNT_MIN
:
316 ((cnt
> QETH_IN_BUF_COUNT_MAX
) ? QETH_IN_BUF_COUNT_MAX
: cnt
);
317 if (old_cnt
!= cnt
) {
318 rc
= qeth_realloc_buffer_pool(card
, cnt
);
321 mutex_unlock(&card
->conf_mutex
);
322 return rc
? rc
: count
;
325 static DEVICE_ATTR(buffer_count
, 0644, qeth_dev_bufcnt_show
,
326 qeth_dev_bufcnt_store
);
328 static ssize_t
qeth_dev_recover_store(struct device
*dev
,
329 struct device_attribute
*attr
, const char *buf
, size_t count
)
331 struct qeth_card
*card
= dev_get_drvdata(dev
);
338 if (card
->state
!= CARD_STATE_UP
)
341 i
= simple_strtoul(buf
, &tmp
, 16);
343 qeth_schedule_recovery(card
);
348 static DEVICE_ATTR(recover
, 0200, NULL
, qeth_dev_recover_store
);
350 static ssize_t
qeth_dev_performance_stats_show(struct device
*dev
,
351 struct device_attribute
*attr
, char *buf
)
353 struct qeth_card
*card
= dev_get_drvdata(dev
);
358 return sprintf(buf
, "%i\n", card
->options
.performance_stats
? 1:0);
361 static ssize_t
qeth_dev_performance_stats_store(struct device
*dev
,
362 struct device_attribute
*attr
, const char *buf
, size_t count
)
364 struct qeth_card
*card
= dev_get_drvdata(dev
);
371 mutex_lock(&card
->conf_mutex
);
372 i
= simple_strtoul(buf
, &tmp
, 16);
373 if ((i
== 0) || (i
== 1)) {
374 if (i
== card
->options
.performance_stats
)
376 card
->options
.performance_stats
= i
;
378 memset(&card
->perf_stats
, 0,
379 sizeof(struct qeth_perf_stats
));
380 card
->perf_stats
.initial_rx_packets
= card
->stats
.rx_packets
;
381 card
->perf_stats
.initial_tx_packets
= card
->stats
.tx_packets
;
385 mutex_unlock(&card
->conf_mutex
);
386 return rc
? rc
: count
;
389 static DEVICE_ATTR(performance_stats
, 0644, qeth_dev_performance_stats_show
,
390 qeth_dev_performance_stats_store
);
392 static ssize_t
qeth_dev_layer2_show(struct device
*dev
,
393 struct device_attribute
*attr
, char *buf
)
395 struct qeth_card
*card
= dev_get_drvdata(dev
);
400 return sprintf(buf
, "%i\n", card
->options
.layer2
);
403 static ssize_t
qeth_dev_layer2_store(struct device
*dev
,
404 struct device_attribute
*attr
, const char *buf
, size_t count
)
406 struct qeth_card
*card
= dev_get_drvdata(dev
);
409 enum qeth_discipline_id newdis
;
414 mutex_lock(&card
->discipline_mutex
);
415 if (card
->state
!= CARD_STATE_DOWN
) {
420 i
= simple_strtoul(buf
, &tmp
, 16);
423 newdis
= QETH_DISCIPLINE_LAYER3
;
426 newdis
= QETH_DISCIPLINE_LAYER2
;
433 if (card
->options
.layer2
== newdis
)
436 card
->info
.mac_bits
= 0;
437 if (card
->discipline
.ccwgdriver
) {
438 card
->discipline
.ccwgdriver
->remove(card
->gdev
);
439 qeth_core_free_discipline(card
);
443 rc
= qeth_core_load_discipline(card
, newdis
);
447 rc
= card
->discipline
.ccwgdriver
->probe(card
->gdev
);
449 mutex_unlock(&card
->discipline_mutex
);
450 return rc
? rc
: count
;
453 static DEVICE_ATTR(layer2
, 0644, qeth_dev_layer2_show
,
454 qeth_dev_layer2_store
);
456 #define ATTR_QETH_ISOLATION_NONE ("none")
457 #define ATTR_QETH_ISOLATION_FWD ("forward")
458 #define ATTR_QETH_ISOLATION_DROP ("drop")
460 static ssize_t
qeth_dev_isolation_show(struct device
*dev
,
461 struct device_attribute
*attr
, char *buf
)
463 struct qeth_card
*card
= dev_get_drvdata(dev
);
468 switch (card
->options
.isolation
) {
469 case ISOLATION_MODE_NONE
:
470 return snprintf(buf
, 6, "%s\n", ATTR_QETH_ISOLATION_NONE
);
471 case ISOLATION_MODE_FWD
:
472 return snprintf(buf
, 9, "%s\n", ATTR_QETH_ISOLATION_FWD
);
473 case ISOLATION_MODE_DROP
:
474 return snprintf(buf
, 6, "%s\n", ATTR_QETH_ISOLATION_DROP
);
476 return snprintf(buf
, 5, "%s\n", "N/A");
480 static ssize_t
qeth_dev_isolation_store(struct device
*dev
,
481 struct device_attribute
*attr
, const char *buf
, size_t count
)
483 struct qeth_card
*card
= dev_get_drvdata(dev
);
484 enum qeth_ipa_isolation_modes isolation
;
486 char *tmp
, *curtoken
;
487 curtoken
= (char *) buf
;
492 mutex_lock(&card
->conf_mutex
);
493 /* check for unknown, too, in case we do not yet know who we are */
494 if (card
->info
.type
!= QETH_CARD_TYPE_OSD
&&
495 card
->info
.type
!= QETH_CARD_TYPE_OSX
&&
496 card
->info
.type
!= QETH_CARD_TYPE_UNKNOWN
) {
498 dev_err(&card
->gdev
->dev
, "Adapter does not "
499 "support QDIO data connection isolation\n");
503 /* parse input into isolation mode */
504 tmp
= strsep(&curtoken
, "\n");
505 if (!strcmp(tmp
, ATTR_QETH_ISOLATION_NONE
)) {
506 isolation
= ISOLATION_MODE_NONE
;
507 } else if (!strcmp(tmp
, ATTR_QETH_ISOLATION_FWD
)) {
508 isolation
= ISOLATION_MODE_FWD
;
509 } else if (!strcmp(tmp
, ATTR_QETH_ISOLATION_DROP
)) {
510 isolation
= ISOLATION_MODE_DROP
;
517 /* defer IP assist if device is offline (until discipline->set_online)*/
518 card
->options
.isolation
= isolation
;
519 if (card
->state
== CARD_STATE_SOFTSETUP
||
520 card
->state
== CARD_STATE_UP
) {
521 int ipa_rc
= qeth_set_access_ctrl_online(card
);
526 mutex_unlock(&card
->conf_mutex
);
530 static DEVICE_ATTR(isolation
, 0644, qeth_dev_isolation_show
,
531 qeth_dev_isolation_store
);
533 static ssize_t
qeth_hw_trap_show(struct device
*dev
,
534 struct device_attribute
*attr
, char *buf
)
536 struct qeth_card
*card
= dev_get_drvdata(dev
);
540 if (card
->info
.hwtrap
)
541 return snprintf(buf
, 5, "arm\n");
543 return snprintf(buf
, 8, "disarm\n");
546 static ssize_t
qeth_hw_trap_store(struct device
*dev
,
547 struct device_attribute
*attr
, const char *buf
, size_t count
)
549 struct qeth_card
*card
= dev_get_drvdata(dev
);
551 char *tmp
, *curtoken
;
553 curtoken
= (char *)buf
;
558 mutex_lock(&card
->conf_mutex
);
559 if (card
->state
== CARD_STATE_SOFTSETUP
|| card
->state
== CARD_STATE_UP
)
561 tmp
= strsep(&curtoken
, "\n");
563 if (!strcmp(tmp
, "arm") && !card
->info
.hwtrap
) {
565 if (qeth_is_diagass_supported(card
,
566 QETH_DIAGS_CMD_TRAP
)) {
567 rc
= qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
);
569 card
->info
.hwtrap
= 1;
573 card
->info
.hwtrap
= 1;
574 } else if (!strcmp(tmp
, "disarm") && card
->info
.hwtrap
) {
576 rc
= qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
578 card
->info
.hwtrap
= 0;
580 card
->info
.hwtrap
= 0;
581 } else if (!strcmp(tmp
, "trap") && state
&& card
->info
.hwtrap
)
582 rc
= qeth_hw_trap(card
, QETH_DIAGS_TRAP_CAPTURE
);
586 mutex_unlock(&card
->conf_mutex
);
587 return rc
? rc
: count
;
590 static DEVICE_ATTR(hw_trap
, 0644, qeth_hw_trap_show
,
593 static ssize_t
qeth_dev_blkt_show(char *buf
, struct qeth_card
*card
, int value
)
599 return sprintf(buf
, "%i\n", value
);
602 static ssize_t
qeth_dev_blkt_store(struct qeth_card
*card
,
603 const char *buf
, size_t count
, int *value
, int max_value
)
611 mutex_lock(&card
->conf_mutex
);
612 if ((card
->state
!= CARD_STATE_DOWN
) &&
613 (card
->state
!= CARD_STATE_RECOVER
)) {
617 i
= simple_strtoul(buf
, &tmp
, 10);
623 mutex_unlock(&card
->conf_mutex
);
624 return rc
? rc
: count
;
627 static ssize_t
qeth_dev_blkt_total_show(struct device
*dev
,
628 struct device_attribute
*attr
, char *buf
)
630 struct qeth_card
*card
= dev_get_drvdata(dev
);
632 return qeth_dev_blkt_show(buf
, card
, card
->info
.blkt
.time_total
);
635 static ssize_t
qeth_dev_blkt_total_store(struct device
*dev
,
636 struct device_attribute
*attr
, const char *buf
, size_t count
)
638 struct qeth_card
*card
= dev_get_drvdata(dev
);
640 return qeth_dev_blkt_store(card
, buf
, count
,
641 &card
->info
.blkt
.time_total
, 5000);
646 static DEVICE_ATTR(total
, 0644, qeth_dev_blkt_total_show
,
647 qeth_dev_blkt_total_store
);
649 static ssize_t
qeth_dev_blkt_inter_show(struct device
*dev
,
650 struct device_attribute
*attr
, char *buf
)
652 struct qeth_card
*card
= dev_get_drvdata(dev
);
654 return qeth_dev_blkt_show(buf
, card
, card
->info
.blkt
.inter_packet
);
657 static ssize_t
qeth_dev_blkt_inter_store(struct device
*dev
,
658 struct device_attribute
*attr
, const char *buf
, size_t count
)
660 struct qeth_card
*card
= dev_get_drvdata(dev
);
662 return qeth_dev_blkt_store(card
, buf
, count
,
663 &card
->info
.blkt
.inter_packet
, 1000);
666 static DEVICE_ATTR(inter
, 0644, qeth_dev_blkt_inter_show
,
667 qeth_dev_blkt_inter_store
);
669 static ssize_t
qeth_dev_blkt_inter_jumbo_show(struct device
*dev
,
670 struct device_attribute
*attr
, char *buf
)
672 struct qeth_card
*card
= dev_get_drvdata(dev
);
674 return qeth_dev_blkt_show(buf
, card
,
675 card
->info
.blkt
.inter_packet_jumbo
);
678 static ssize_t
qeth_dev_blkt_inter_jumbo_store(struct device
*dev
,
679 struct device_attribute
*attr
, const char *buf
, size_t count
)
681 struct qeth_card
*card
= dev_get_drvdata(dev
);
683 return qeth_dev_blkt_store(card
, buf
, count
,
684 &card
->info
.blkt
.inter_packet_jumbo
, 1000);
687 static DEVICE_ATTR(inter_jumbo
, 0644, qeth_dev_blkt_inter_jumbo_show
,
688 qeth_dev_blkt_inter_jumbo_store
);
690 static struct attribute
*qeth_blkt_device_attrs
[] = {
691 &dev_attr_total
.attr
,
692 &dev_attr_inter
.attr
,
693 &dev_attr_inter_jumbo
.attr
,
697 static struct attribute_group qeth_device_blkt_group
= {
699 .attrs
= qeth_blkt_device_attrs
,
702 static struct attribute
*qeth_device_attrs
[] = {
703 &dev_attr_state
.attr
,
704 &dev_attr_chpid
.attr
,
705 &dev_attr_if_name
.attr
,
706 &dev_attr_card_type
.attr
,
707 &dev_attr_inbuf_size
.attr
,
708 &dev_attr_portno
.attr
,
709 &dev_attr_portname
.attr
,
710 &dev_attr_priority_queueing
.attr
,
711 &dev_attr_buffer_count
.attr
,
712 &dev_attr_recover
.attr
,
713 &dev_attr_performance_stats
.attr
,
714 &dev_attr_layer2
.attr
,
715 &dev_attr_isolation
.attr
,
716 &dev_attr_hw_trap
.attr
,
720 static struct attribute_group qeth_device_attr_group
= {
721 .attrs
= qeth_device_attrs
,
724 static struct attribute
*qeth_osn_device_attrs
[] = {
725 &dev_attr_state
.attr
,
726 &dev_attr_chpid
.attr
,
727 &dev_attr_if_name
.attr
,
728 &dev_attr_card_type
.attr
,
729 &dev_attr_buffer_count
.attr
,
730 &dev_attr_recover
.attr
,
734 static struct attribute_group qeth_osn_device_attr_group
= {
735 .attrs
= qeth_osn_device_attrs
,
738 int qeth_core_create_device_attributes(struct device
*dev
)
741 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_attr_group
);
744 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_blkt_group
);
746 sysfs_remove_group(&dev
->kobj
, &qeth_device_attr_group
);
751 void qeth_core_remove_device_attributes(struct device
*dev
)
753 sysfs_remove_group(&dev
->kobj
, &qeth_device_attr_group
);
754 sysfs_remove_group(&dev
->kobj
, &qeth_device_blkt_group
);
757 int qeth_core_create_osn_attributes(struct device
*dev
)
759 return sysfs_create_group(&dev
->kobj
, &qeth_osn_device_attr_group
);
762 void qeth_core_remove_osn_attributes(struct device
*dev
)
764 sysfs_remove_group(&dev
->kobj
, &qeth_osn_device_attr_group
);