1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2007
4 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
10 #define KMSG_COMPONENT "qeth"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/list.h>
14 #include <linux/rwsem.h>
15 #include <asm/ebcdic.h>
17 #include "qeth_core.h"
19 static ssize_t
qeth_dev_state_show(struct device
*dev
,
20 struct device_attribute
*attr
, char *buf
)
22 struct qeth_card
*card
= dev_get_drvdata(dev
);
24 switch (card
->state
) {
26 return sysfs_emit(buf
, "DOWN\n");
27 case CARD_STATE_SOFTSETUP
:
28 if (card
->dev
->flags
& IFF_UP
)
29 return sysfs_emit(buf
, "UP (LAN %s)\n",
30 netif_carrier_ok(card
->dev
) ?
31 "ONLINE" : "OFFLINE");
32 return sysfs_emit(buf
, "SOFTSETUP\n");
34 return sysfs_emit(buf
, "UNKNOWN\n");
38 static DEVICE_ATTR(state
, 0444, qeth_dev_state_show
, NULL
);
40 static ssize_t
qeth_dev_chpid_show(struct device
*dev
,
41 struct device_attribute
*attr
, char *buf
)
43 struct qeth_card
*card
= dev_get_drvdata(dev
);
45 return sysfs_emit(buf
, "%02X\n", card
->info
.chpid
);
48 static DEVICE_ATTR(chpid
, 0444, qeth_dev_chpid_show
, NULL
);
50 static ssize_t
qeth_dev_if_name_show(struct device
*dev
,
51 struct device_attribute
*attr
, char *buf
)
53 struct qeth_card
*card
= dev_get_drvdata(dev
);
55 return sysfs_emit(buf
, "%s\n", netdev_name(card
->dev
));
58 static DEVICE_ATTR(if_name
, 0444, qeth_dev_if_name_show
, NULL
);
60 static ssize_t
qeth_dev_card_type_show(struct device
*dev
,
61 struct device_attribute
*attr
, char *buf
)
63 struct qeth_card
*card
= dev_get_drvdata(dev
);
65 return sysfs_emit(buf
, "%s\n", qeth_get_cardname_short(card
));
68 static DEVICE_ATTR(card_type
, 0444, qeth_dev_card_type_show
, NULL
);
70 static const char *qeth_get_bufsize_str(struct qeth_card
*card
)
72 if (card
->qdio
.in_buf_size
== 16384)
74 else if (card
->qdio
.in_buf_size
== 24576)
76 else if (card
->qdio
.in_buf_size
== 32768)
78 else if (card
->qdio
.in_buf_size
== 40960)
84 static ssize_t
qeth_dev_inbuf_size_show(struct device
*dev
,
85 struct device_attribute
*attr
, char *buf
)
87 struct qeth_card
*card
= dev_get_drvdata(dev
);
89 return sysfs_emit(buf
, "%s\n", qeth_get_bufsize_str(card
));
92 static DEVICE_ATTR(inbuf_size
, 0444, qeth_dev_inbuf_size_show
, NULL
);
94 static ssize_t
qeth_dev_portno_show(struct device
*dev
,
95 struct device_attribute
*attr
, char *buf
)
97 struct qeth_card
*card
= dev_get_drvdata(dev
);
99 return sysfs_emit(buf
, "%i\n", card
->dev
->dev_port
);
102 static ssize_t
qeth_dev_portno_store(struct device
*dev
,
103 struct device_attribute
*attr
, const char *buf
, size_t count
)
105 struct qeth_card
*card
= dev_get_drvdata(dev
);
106 unsigned int portno
, limit
;
109 rc
= kstrtouint(buf
, 16, &portno
);
112 if (portno
> QETH_MAX_PORTNO
)
115 mutex_lock(&card
->conf_mutex
);
116 if (card
->state
!= CARD_STATE_DOWN
) {
121 limit
= (card
->ssqd
.pcnt
? card
->ssqd
.pcnt
- 1 : card
->ssqd
.pcnt
);
122 if (portno
> limit
) {
126 card
->dev
->dev_port
= portno
;
128 mutex_unlock(&card
->conf_mutex
);
129 return rc
? rc
: count
;
132 static DEVICE_ATTR(portno
, 0644, qeth_dev_portno_show
, qeth_dev_portno_store
);
134 static ssize_t
qeth_dev_portname_show(struct device
*dev
,
135 struct device_attribute
*attr
, char *buf
)
137 return sysfs_emit(buf
, "no portname required\n");
140 static ssize_t
qeth_dev_portname_store(struct device
*dev
,
141 struct device_attribute
*attr
, const char *buf
, size_t count
)
143 struct qeth_card
*card
= dev_get_drvdata(dev
);
145 dev_warn_once(&card
->gdev
->dev
,
146 "portname is deprecated and is ignored\n");
150 static DEVICE_ATTR(portname
, 0644, qeth_dev_portname_show
,
151 qeth_dev_portname_store
);
153 static ssize_t
qeth_dev_prioqing_show(struct device
*dev
,
154 struct device_attribute
*attr
, char *buf
)
156 struct qeth_card
*card
= dev_get_drvdata(dev
);
158 switch (card
->qdio
.do_prio_queueing
) {
159 case QETH_PRIO_Q_ING_PREC
:
160 return sysfs_emit(buf
, "%s\n", "by precedence");
161 case QETH_PRIO_Q_ING_TOS
:
162 return sysfs_emit(buf
, "%s\n", "by type of service");
163 case QETH_PRIO_Q_ING_SKB
:
164 return sysfs_emit(buf
, "%s\n", "by skb-priority");
165 case QETH_PRIO_Q_ING_VLAN
:
166 return sysfs_emit(buf
, "%s\n", "by VLAN headers");
167 case QETH_PRIO_Q_ING_FIXED
:
168 return sysfs_emit(buf
, "always queue %i\n",
169 card
->qdio
.default_out_queue
);
171 return sysfs_emit(buf
, "disabled\n");
175 static ssize_t
qeth_dev_prioqing_store(struct device
*dev
,
176 struct device_attribute
*attr
, const char *buf
, size_t count
)
178 struct qeth_card
*card
= dev_get_drvdata(dev
);
181 if (IS_IQD(card
) || IS_VM_NIC(card
))
184 mutex_lock(&card
->conf_mutex
);
185 if (card
->state
!= CARD_STATE_DOWN
) {
190 /* check if 1920 devices are supported ,
191 * if though we have to permit priority queueing
193 if (card
->qdio
.no_out_queues
== 1) {
194 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
199 if (sysfs_streq(buf
, "prio_queueing_prec")) {
200 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_PREC
;
201 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
202 } else if (sysfs_streq(buf
, "prio_queueing_skb")) {
203 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_SKB
;
204 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
205 } else if (sysfs_streq(buf
, "prio_queueing_tos")) {
206 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_TOS
;
207 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
208 } else if (sysfs_streq(buf
, "prio_queueing_vlan")) {
209 if (IS_LAYER3(card
)) {
213 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_VLAN
;
214 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
215 } else if (sysfs_streq(buf
, "no_prio_queueing:0")) {
216 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_FIXED
;
217 card
->qdio
.default_out_queue
= 0;
218 } else if (sysfs_streq(buf
, "no_prio_queueing:1")) {
219 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_FIXED
;
220 card
->qdio
.default_out_queue
= 1;
221 } else if (sysfs_streq(buf
, "no_prio_queueing:2")) {
222 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_FIXED
;
223 card
->qdio
.default_out_queue
= 2;
224 } else if (sysfs_streq(buf
, "no_prio_queueing:3")) {
225 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_FIXED
;
226 card
->qdio
.default_out_queue
= 3;
227 } else if (sysfs_streq(buf
, "no_prio_queueing")) {
228 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
229 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
233 mutex_unlock(&card
->conf_mutex
);
234 return rc
? rc
: count
;
237 static DEVICE_ATTR(priority_queueing
, 0644, qeth_dev_prioqing_show
,
238 qeth_dev_prioqing_store
);
240 static ssize_t
qeth_dev_bufcnt_show(struct device
*dev
,
241 struct device_attribute
*attr
, char *buf
)
243 struct qeth_card
*card
= dev_get_drvdata(dev
);
245 return sysfs_emit(buf
, "%i\n", card
->qdio
.in_buf_pool
.buf_count
);
248 static ssize_t
qeth_dev_bufcnt_store(struct device
*dev
,
249 struct device_attribute
*attr
, const char *buf
, size_t count
)
251 struct qeth_card
*card
= dev_get_drvdata(dev
);
255 rc
= kstrtouint(buf
, 10, &cnt
);
259 mutex_lock(&card
->conf_mutex
);
260 if (card
->state
!= CARD_STATE_DOWN
) {
265 cnt
= clamp(cnt
, QETH_IN_BUF_COUNT_MIN
, QETH_IN_BUF_COUNT_MAX
);
266 rc
= qeth_resize_buffer_pool(card
, cnt
);
269 mutex_unlock(&card
->conf_mutex
);
270 return rc
? rc
: count
;
273 static DEVICE_ATTR(buffer_count
, 0644, qeth_dev_bufcnt_show
,
274 qeth_dev_bufcnt_store
);
276 static ssize_t
qeth_dev_recover_store(struct device
*dev
,
277 struct device_attribute
*attr
, const char *buf
, size_t count
)
279 struct qeth_card
*card
= dev_get_drvdata(dev
);
283 rc
= kstrtobool(buf
, &reset
);
287 if (!qeth_card_hw_is_reachable(card
))
291 rc
= qeth_schedule_recovery(card
);
293 return rc
? rc
: count
;
296 static DEVICE_ATTR(recover
, 0200, NULL
, qeth_dev_recover_store
);
298 static ssize_t
qeth_dev_performance_stats_show(struct device
*dev
,
299 struct device_attribute
*attr
, char *buf
)
301 return sysfs_emit(buf
, "1\n");
304 static ssize_t
qeth_dev_performance_stats_store(struct device
*dev
,
305 struct device_attribute
*attr
, const char *buf
, size_t count
)
307 struct qeth_card
*card
= dev_get_drvdata(dev
);
308 struct qeth_qdio_out_q
*queue
;
313 rc
= kstrtobool(buf
, &reset
);
318 memset(&card
->stats
, 0, sizeof(card
->stats
));
319 for (i
= 0; i
< card
->qdio
.no_out_queues
; i
++) {
320 queue
= card
->qdio
.out_qs
[i
];
323 memset(&queue
->stats
, 0, sizeof(queue
->stats
));
330 static DEVICE_ATTR(performance_stats
, 0644, qeth_dev_performance_stats_show
,
331 qeth_dev_performance_stats_store
);
333 static ssize_t
qeth_dev_layer2_show(struct device
*dev
,
334 struct device_attribute
*attr
, char *buf
)
336 struct qeth_card
*card
= dev_get_drvdata(dev
);
338 return sysfs_emit(buf
, "%i\n", card
->options
.layer
);
341 static ssize_t
qeth_dev_layer2_store(struct device
*dev
,
342 struct device_attribute
*attr
, const char *buf
, size_t count
)
344 struct qeth_card
*card
= dev_get_drvdata(dev
);
345 struct net_device
*ndev
;
346 enum qeth_discipline_id newdis
;
350 rc
= kstrtouint(buf
, 16, &input
);
356 newdis
= QETH_DISCIPLINE_LAYER3
;
359 newdis
= QETH_DISCIPLINE_LAYER2
;
365 mutex_lock(&card
->discipline_mutex
);
366 if (card
->state
!= CARD_STATE_DOWN
) {
371 if (card
->options
.layer
== newdis
)
373 if (card
->info
.layer_enforced
) {
374 /* fixed layer, can't switch */
379 if (card
->discipline
) {
380 /* start with a new, pristine netdevice: */
381 ndev
= qeth_clone_netdev(card
->dev
);
387 qeth_remove_discipline(card
);
388 free_netdev(card
->dev
);
392 rc
= qeth_setup_discipline(card
, newdis
);
395 mutex_unlock(&card
->discipline_mutex
);
396 return rc
? rc
: count
;
399 static DEVICE_ATTR(layer2
, 0644, qeth_dev_layer2_show
,
400 qeth_dev_layer2_store
);
402 #define ATTR_QETH_ISOLATION_NONE ("none")
403 #define ATTR_QETH_ISOLATION_FWD ("forward")
404 #define ATTR_QETH_ISOLATION_DROP ("drop")
406 static ssize_t
qeth_dev_isolation_show(struct device
*dev
,
407 struct device_attribute
*attr
, char *buf
)
409 struct qeth_card
*card
= dev_get_drvdata(dev
);
411 switch (card
->options
.isolation
) {
412 case ISOLATION_MODE_NONE
:
413 return sysfs_emit(buf
, "%s\n", ATTR_QETH_ISOLATION_NONE
);
414 case ISOLATION_MODE_FWD
:
415 return sysfs_emit(buf
, "%s\n", ATTR_QETH_ISOLATION_FWD
);
416 case ISOLATION_MODE_DROP
:
417 return sysfs_emit(buf
, "%s\n", ATTR_QETH_ISOLATION_DROP
);
419 return sysfs_emit(buf
, "%s\n", "N/A");
423 static ssize_t
qeth_dev_isolation_store(struct device
*dev
,
424 struct device_attribute
*attr
, const char *buf
, size_t count
)
426 struct qeth_card
*card
= dev_get_drvdata(dev
);
427 enum qeth_ipa_isolation_modes isolation
;
430 mutex_lock(&card
->conf_mutex
);
431 if (!IS_OSD(card
) && !IS_OSX(card
)) {
433 dev_err(&card
->gdev
->dev
, "Adapter does not "
434 "support QDIO data connection isolation\n");
438 /* parse input into isolation mode */
439 if (sysfs_streq(buf
, ATTR_QETH_ISOLATION_NONE
)) {
440 isolation
= ISOLATION_MODE_NONE
;
441 } else if (sysfs_streq(buf
, ATTR_QETH_ISOLATION_FWD
)) {
442 isolation
= ISOLATION_MODE_FWD
;
443 } else if (sysfs_streq(buf
, ATTR_QETH_ISOLATION_DROP
)) {
444 isolation
= ISOLATION_MODE_DROP
;
450 if (qeth_card_hw_is_reachable(card
))
451 rc
= qeth_setadpparms_set_access_ctrl(card
, isolation
);
454 WRITE_ONCE(card
->options
.isolation
, isolation
);
457 mutex_unlock(&card
->conf_mutex
);
459 return rc
? rc
: count
;
462 static DEVICE_ATTR(isolation
, 0644, qeth_dev_isolation_show
,
463 qeth_dev_isolation_store
);
465 static ssize_t
qeth_dev_switch_attrs_show(struct device
*dev
,
466 struct device_attribute
*attr
, char *buf
)
468 struct qeth_card
*card
= dev_get_drvdata(dev
);
469 struct qeth_switch_info sw_info
;
472 if (!qeth_card_hw_is_reachable(card
))
473 return sysfs_emit(buf
, "n/a\n");
475 rc
= qeth_query_switch_attributes(card
, &sw_info
);
479 if (!sw_info
.capabilities
)
480 rc
= sysfs_emit(buf
, "unknown");
482 if (sw_info
.capabilities
& QETH_SWITCH_FORW_802_1
)
484 (sw_info
.settings
& QETH_SWITCH_FORW_802_1
?
485 "[802.1]" : "802.1"));
486 if (sw_info
.capabilities
& QETH_SWITCH_FORW_REFL_RELAY
)
487 rc
+= sysfs_emit_at(buf
, rc
,
489 QETH_SWITCH_FORW_REFL_RELAY
?
491 rc
+= sysfs_emit_at(buf
, rc
, "\n");
496 static DEVICE_ATTR(switch_attrs
, 0444,
497 qeth_dev_switch_attrs_show
, NULL
);
499 static ssize_t
qeth_hw_trap_show(struct device
*dev
,
500 struct device_attribute
*attr
, char *buf
)
502 struct qeth_card
*card
= dev_get_drvdata(dev
);
504 if (card
->info
.hwtrap
)
505 return sysfs_emit(buf
, "arm\n");
507 return sysfs_emit(buf
, "disarm\n");
510 static ssize_t
qeth_hw_trap_store(struct device
*dev
,
511 struct device_attribute
*attr
, const char *buf
, size_t count
)
513 struct qeth_card
*card
= dev_get_drvdata(dev
);
517 mutex_lock(&card
->conf_mutex
);
518 if (qeth_card_hw_is_reachable(card
))
521 if (sysfs_streq(buf
, "arm") && !card
->info
.hwtrap
) {
523 if (qeth_is_diagass_supported(card
,
524 QETH_DIAGS_CMD_TRAP
)) {
525 rc
= qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
);
527 card
->info
.hwtrap
= 1;
531 card
->info
.hwtrap
= 1;
532 } else if (sysfs_streq(buf
, "disarm") && card
->info
.hwtrap
) {
534 rc
= qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
536 card
->info
.hwtrap
= 0;
538 card
->info
.hwtrap
= 0;
539 } else if (sysfs_streq(buf
, "trap") && state
&& card
->info
.hwtrap
)
540 rc
= qeth_hw_trap(card
, QETH_DIAGS_TRAP_CAPTURE
);
544 mutex_unlock(&card
->conf_mutex
);
545 return rc
? rc
: count
;
548 static DEVICE_ATTR(hw_trap
, 0644, qeth_hw_trap_show
,
551 static ssize_t
qeth_dev_blkt_store(struct qeth_card
*card
,
552 const char *buf
, size_t count
, int *value
, int max_value
)
557 rc
= kstrtouint(buf
, 10, &input
);
561 if (input
> max_value
)
564 mutex_lock(&card
->conf_mutex
);
565 if (card
->state
!= CARD_STATE_DOWN
)
569 mutex_unlock(&card
->conf_mutex
);
570 return rc
? rc
: count
;
573 static ssize_t
qeth_dev_blkt_total_show(struct device
*dev
,
574 struct device_attribute
*attr
, char *buf
)
576 struct qeth_card
*card
= dev_get_drvdata(dev
);
578 return sysfs_emit(buf
, "%i\n", card
->info
.blkt
.time_total
);
581 static ssize_t
qeth_dev_blkt_total_store(struct device
*dev
,
582 struct device_attribute
*attr
, const char *buf
, size_t count
)
584 struct qeth_card
*card
= dev_get_drvdata(dev
);
586 return qeth_dev_blkt_store(card
, buf
, count
,
587 &card
->info
.blkt
.time_total
, 5000);
590 static DEVICE_ATTR(total
, 0644, qeth_dev_blkt_total_show
,
591 qeth_dev_blkt_total_store
);
593 static ssize_t
qeth_dev_blkt_inter_show(struct device
*dev
,
594 struct device_attribute
*attr
, char *buf
)
596 struct qeth_card
*card
= dev_get_drvdata(dev
);
598 return sysfs_emit(buf
, "%i\n", card
->info
.blkt
.inter_packet
);
601 static ssize_t
qeth_dev_blkt_inter_store(struct device
*dev
,
602 struct device_attribute
*attr
, const char *buf
, size_t count
)
604 struct qeth_card
*card
= dev_get_drvdata(dev
);
606 return qeth_dev_blkt_store(card
, buf
, count
,
607 &card
->info
.blkt
.inter_packet
, 1000);
610 static DEVICE_ATTR(inter
, 0644, qeth_dev_blkt_inter_show
,
611 qeth_dev_blkt_inter_store
);
613 static ssize_t
qeth_dev_blkt_inter_jumbo_show(struct device
*dev
,
614 struct device_attribute
*attr
, char *buf
)
616 struct qeth_card
*card
= dev_get_drvdata(dev
);
618 return sysfs_emit(buf
, "%i\n", card
->info
.blkt
.inter_packet_jumbo
);
621 static ssize_t
qeth_dev_blkt_inter_jumbo_store(struct device
*dev
,
622 struct device_attribute
*attr
, const char *buf
, size_t count
)
624 struct qeth_card
*card
= dev_get_drvdata(dev
);
626 return qeth_dev_blkt_store(card
, buf
, count
,
627 &card
->info
.blkt
.inter_packet_jumbo
, 1000);
630 static DEVICE_ATTR(inter_jumbo
, 0644, qeth_dev_blkt_inter_jumbo_show
,
631 qeth_dev_blkt_inter_jumbo_store
);
633 static struct attribute
*qeth_blkt_device_attrs
[] = {
634 &dev_attr_total
.attr
,
635 &dev_attr_inter
.attr
,
636 &dev_attr_inter_jumbo
.attr
,
640 static const struct attribute_group qeth_dev_blkt_group
= {
642 .attrs
= qeth_blkt_device_attrs
,
645 static struct attribute
*qeth_dev_extended_attrs
[] = {
646 &dev_attr_inbuf_size
.attr
,
647 &dev_attr_portno
.attr
,
648 &dev_attr_portname
.attr
,
649 &dev_attr_priority_queueing
.attr
,
650 &dev_attr_performance_stats
.attr
,
651 &dev_attr_layer2
.attr
,
652 &dev_attr_isolation
.attr
,
653 &dev_attr_hw_trap
.attr
,
654 &dev_attr_switch_attrs
.attr
,
658 static const struct attribute_group qeth_dev_extended_group
= {
659 .attrs
= qeth_dev_extended_attrs
,
662 static struct attribute
*qeth_dev_attrs
[] = {
663 &dev_attr_state
.attr
,
664 &dev_attr_chpid
.attr
,
665 &dev_attr_if_name
.attr
,
666 &dev_attr_card_type
.attr
,
667 &dev_attr_buffer_count
.attr
,
668 &dev_attr_recover
.attr
,
672 static const struct attribute_group qeth_dev_group
= {
673 .attrs
= qeth_dev_attrs
,
676 const struct attribute_group
*qeth_dev_groups
[] = {
678 &qeth_dev_extended_group
,
679 &qeth_dev_blkt_group
,