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 sprintf(buf
, "DOWN\n");
27 case CARD_STATE_SOFTSETUP
:
28 if (card
->dev
->flags
& IFF_UP
)
29 return sprintf(buf
, "UP (LAN %s)\n",
30 netif_carrier_ok(card
->dev
) ? "ONLINE" :
32 return sprintf(buf
, "SOFTSETUP\n");
34 return sprintf(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 sprintf(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 sprintf(buf
, "%s\n", QETH_CARD_IFNAME(card
));
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 sprintf(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 sprintf(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 sprintf(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
);
107 unsigned int portno
, limit
;
110 mutex_lock(&card
->conf_mutex
);
111 if (card
->state
!= CARD_STATE_DOWN
) {
116 portno
= simple_strtoul(buf
, &tmp
, 16);
117 if (portno
> QETH_MAX_PORTNO
) {
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 sprintf(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 sprintf(buf
, "%s\n", "by precedence");
161 case QETH_PRIO_Q_ING_TOS
:
162 return sprintf(buf
, "%s\n", "by type of service");
163 case QETH_PRIO_Q_ING_SKB
:
164 return sprintf(buf
, "%s\n", "by skb-priority");
165 case QETH_PRIO_Q_ING_VLAN
:
166 return sprintf(buf
, "%s\n", "by VLAN headers");
168 return sprintf(buf
, "always queue %i\n",
169 card
->qdio
.default_out_queue
);
173 static ssize_t
qeth_dev_prioqing_store(struct device
*dev
,
174 struct device_attribute
*attr
, const char *buf
, size_t count
)
176 struct qeth_card
*card
= dev_get_drvdata(dev
);
182 mutex_lock(&card
->conf_mutex
);
183 if (card
->state
!= CARD_STATE_DOWN
) {
188 /* check if 1920 devices are supported ,
189 * if though we have to permit priority queueing
191 if (card
->qdio
.no_out_queues
== 1) {
192 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
197 if (sysfs_streq(buf
, "prio_queueing_prec")) {
198 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_PREC
;
199 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
200 } else if (sysfs_streq(buf
, "prio_queueing_skb")) {
201 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_SKB
;
202 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
203 } else if (sysfs_streq(buf
, "prio_queueing_tos")) {
204 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_TOS
;
205 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
206 } else if (sysfs_streq(buf
, "prio_queueing_vlan")) {
207 if (IS_LAYER3(card
)) {
211 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_VLAN
;
212 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
213 } else if (sysfs_streq(buf
, "no_prio_queueing:0")) {
214 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
215 card
->qdio
.default_out_queue
= 0;
216 } else if (sysfs_streq(buf
, "no_prio_queueing:1")) {
217 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
218 card
->qdio
.default_out_queue
= 1;
219 } else if (sysfs_streq(buf
, "no_prio_queueing:2")) {
220 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
221 card
->qdio
.default_out_queue
= 2;
222 } else if (sysfs_streq(buf
, "no_prio_queueing:3")) {
223 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
224 card
->qdio
.default_out_queue
= 3;
225 } else if (sysfs_streq(buf
, "no_prio_queueing")) {
226 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
227 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
231 mutex_unlock(&card
->conf_mutex
);
232 return rc
? rc
: count
;
235 static DEVICE_ATTR(priority_queueing
, 0644, qeth_dev_prioqing_show
,
236 qeth_dev_prioqing_store
);
238 static ssize_t
qeth_dev_bufcnt_show(struct device
*dev
,
239 struct device_attribute
*attr
, char *buf
)
241 struct qeth_card
*card
= dev_get_drvdata(dev
);
243 return sprintf(buf
, "%i\n", card
->qdio
.in_buf_pool
.buf_count
);
246 static ssize_t
qeth_dev_bufcnt_store(struct device
*dev
,
247 struct device_attribute
*attr
, const char *buf
, size_t count
)
249 struct qeth_card
*card
= dev_get_drvdata(dev
);
254 mutex_lock(&card
->conf_mutex
);
255 if (card
->state
!= CARD_STATE_DOWN
) {
260 old_cnt
= card
->qdio
.in_buf_pool
.buf_count
;
261 cnt
= simple_strtoul(buf
, &tmp
, 10);
262 cnt
= (cnt
< QETH_IN_BUF_COUNT_MIN
) ? QETH_IN_BUF_COUNT_MIN
:
263 ((cnt
> QETH_IN_BUF_COUNT_MAX
) ? QETH_IN_BUF_COUNT_MAX
: cnt
);
264 if (old_cnt
!= cnt
) {
265 rc
= qeth_realloc_buffer_pool(card
, cnt
);
268 mutex_unlock(&card
->conf_mutex
);
269 return rc
? rc
: count
;
272 static DEVICE_ATTR(buffer_count
, 0644, qeth_dev_bufcnt_show
,
273 qeth_dev_bufcnt_store
);
275 static ssize_t
qeth_dev_recover_store(struct device
*dev
,
276 struct device_attribute
*attr
, const char *buf
, size_t count
)
278 struct qeth_card
*card
= dev_get_drvdata(dev
);
282 if (!qeth_card_hw_is_reachable(card
))
285 i
= simple_strtoul(buf
, &tmp
, 16);
287 qeth_schedule_recovery(card
);
292 static DEVICE_ATTR(recover
, 0200, NULL
, qeth_dev_recover_store
);
294 static ssize_t
qeth_dev_performance_stats_show(struct device
*dev
,
295 struct device_attribute
*attr
, char *buf
)
297 return sprintf(buf
, "1\n");
300 static ssize_t
qeth_dev_performance_stats_store(struct device
*dev
,
301 struct device_attribute
*attr
, const char *buf
, size_t count
)
303 struct qeth_card
*card
= dev_get_drvdata(dev
);
304 struct qeth_qdio_out_q
*queue
;
309 rc
= kstrtobool(buf
, &reset
);
314 memset(&card
->stats
, 0, sizeof(card
->stats
));
315 for (i
= 0; i
< card
->qdio
.no_out_queues
; i
++) {
316 queue
= card
->qdio
.out_qs
[i
];
319 memset(&queue
->stats
, 0, sizeof(queue
->stats
));
326 static DEVICE_ATTR(performance_stats
, 0644, qeth_dev_performance_stats_show
,
327 qeth_dev_performance_stats_store
);
329 static ssize_t
qeth_dev_layer2_show(struct device
*dev
,
330 struct device_attribute
*attr
, char *buf
)
332 struct qeth_card
*card
= dev_get_drvdata(dev
);
334 return sprintf(buf
, "%i\n", card
->options
.layer
);
337 static ssize_t
qeth_dev_layer2_store(struct device
*dev
,
338 struct device_attribute
*attr
, const char *buf
, size_t count
)
340 struct qeth_card
*card
= dev_get_drvdata(dev
);
341 struct net_device
*ndev
;
344 enum qeth_discipline_id newdis
;
346 mutex_lock(&card
->discipline_mutex
);
347 if (card
->state
!= CARD_STATE_DOWN
) {
352 i
= simple_strtoul(buf
, &tmp
, 16);
355 newdis
= QETH_DISCIPLINE_LAYER3
;
358 newdis
= QETH_DISCIPLINE_LAYER2
;
365 if (card
->options
.layer
== newdis
)
367 if (card
->info
.layer_enforced
) {
368 /* fixed layer, can't switch */
373 if (card
->discipline
) {
374 /* start with a new, pristine netdevice: */
375 ndev
= qeth_clone_netdev(card
->dev
);
381 card
->discipline
->remove(card
->gdev
);
382 qeth_core_free_discipline(card
);
383 free_netdev(card
->dev
);
387 rc
= qeth_core_load_discipline(card
, newdis
);
391 rc
= card
->discipline
->setup(card
->gdev
);
393 qeth_core_free_discipline(card
);
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 snprintf(buf
, 6, "%s\n", ATTR_QETH_ISOLATION_NONE
);
414 case ISOLATION_MODE_FWD
:
415 return snprintf(buf
, 9, "%s\n", ATTR_QETH_ISOLATION_FWD
);
416 case ISOLATION_MODE_DROP
:
417 return snprintf(buf
, 6, "%s\n", ATTR_QETH_ISOLATION_DROP
);
419 return snprintf(buf
, 5, "%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
;
451 /* defer IP assist if device is offline (until discipline->set_online)*/
452 card
->options
.prev_isolation
= card
->options
.isolation
;
453 card
->options
.isolation
= isolation
;
454 if (qeth_card_hw_is_reachable(card
)) {
455 int ipa_rc
= qeth_set_access_ctrl_online(card
, 1);
460 mutex_unlock(&card
->conf_mutex
);
464 static DEVICE_ATTR(isolation
, 0644, qeth_dev_isolation_show
,
465 qeth_dev_isolation_store
);
467 static ssize_t
qeth_dev_switch_attrs_show(struct device
*dev
,
468 struct device_attribute
*attr
, char *buf
)
470 struct qeth_card
*card
= dev_get_drvdata(dev
);
471 struct qeth_switch_info sw_info
;
474 if (!qeth_card_hw_is_reachable(card
))
475 return sprintf(buf
, "n/a\n");
477 rc
= qeth_query_switch_attributes(card
, &sw_info
);
481 if (!sw_info
.capabilities
)
482 rc
= sprintf(buf
, "unknown");
484 if (sw_info
.capabilities
& QETH_SWITCH_FORW_802_1
)
485 rc
= sprintf(buf
, (sw_info
.settings
& QETH_SWITCH_FORW_802_1
?
486 "[802.1]" : "802.1"));
487 if (sw_info
.capabilities
& QETH_SWITCH_FORW_REFL_RELAY
)
488 rc
+= sprintf(buf
+ rc
,
489 (sw_info
.settings
& QETH_SWITCH_FORW_REFL_RELAY
?
491 rc
+= sprintf(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 snprintf(buf
, 5, "arm\n");
507 return snprintf(buf
, 8, "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 mutex_lock(&card
->conf_mutex
);
558 if (card
->state
!= CARD_STATE_DOWN
) {
562 i
= simple_strtoul(buf
, &tmp
, 10);
568 mutex_unlock(&card
->conf_mutex
);
569 return rc
? rc
: count
;
572 static ssize_t
qeth_dev_blkt_total_show(struct device
*dev
,
573 struct device_attribute
*attr
, char *buf
)
575 struct qeth_card
*card
= dev_get_drvdata(dev
);
577 return sprintf(buf
, "%i\n", card
->info
.blkt
.time_total
);
580 static ssize_t
qeth_dev_blkt_total_store(struct device
*dev
,
581 struct device_attribute
*attr
, const char *buf
, size_t count
)
583 struct qeth_card
*card
= dev_get_drvdata(dev
);
585 return qeth_dev_blkt_store(card
, buf
, count
,
586 &card
->info
.blkt
.time_total
, 5000);
589 static DEVICE_ATTR(total
, 0644, qeth_dev_blkt_total_show
,
590 qeth_dev_blkt_total_store
);
592 static ssize_t
qeth_dev_blkt_inter_show(struct device
*dev
,
593 struct device_attribute
*attr
, char *buf
)
595 struct qeth_card
*card
= dev_get_drvdata(dev
);
597 return sprintf(buf
, "%i\n", card
->info
.blkt
.inter_packet
);
600 static ssize_t
qeth_dev_blkt_inter_store(struct device
*dev
,
601 struct device_attribute
*attr
, const char *buf
, size_t count
)
603 struct qeth_card
*card
= dev_get_drvdata(dev
);
605 return qeth_dev_blkt_store(card
, buf
, count
,
606 &card
->info
.blkt
.inter_packet
, 1000);
609 static DEVICE_ATTR(inter
, 0644, qeth_dev_blkt_inter_show
,
610 qeth_dev_blkt_inter_store
);
612 static ssize_t
qeth_dev_blkt_inter_jumbo_show(struct device
*dev
,
613 struct device_attribute
*attr
, char *buf
)
615 struct qeth_card
*card
= dev_get_drvdata(dev
);
617 return sprintf(buf
, "%i\n", card
->info
.blkt
.inter_packet_jumbo
);
620 static ssize_t
qeth_dev_blkt_inter_jumbo_store(struct device
*dev
,
621 struct device_attribute
*attr
, const char *buf
, size_t count
)
623 struct qeth_card
*card
= dev_get_drvdata(dev
);
625 return qeth_dev_blkt_store(card
, buf
, count
,
626 &card
->info
.blkt
.inter_packet_jumbo
, 1000);
629 static DEVICE_ATTR(inter_jumbo
, 0644, qeth_dev_blkt_inter_jumbo_show
,
630 qeth_dev_blkt_inter_jumbo_store
);
632 static struct attribute
*qeth_blkt_device_attrs
[] = {
633 &dev_attr_total
.attr
,
634 &dev_attr_inter
.attr
,
635 &dev_attr_inter_jumbo
.attr
,
638 const struct attribute_group qeth_device_blkt_group
= {
640 .attrs
= qeth_blkt_device_attrs
,
642 EXPORT_SYMBOL_GPL(qeth_device_blkt_group
);
644 static struct attribute
*qeth_device_attrs
[] = {
645 &dev_attr_state
.attr
,
646 &dev_attr_chpid
.attr
,
647 &dev_attr_if_name
.attr
,
648 &dev_attr_card_type
.attr
,
649 &dev_attr_inbuf_size
.attr
,
650 &dev_attr_portno
.attr
,
651 &dev_attr_portname
.attr
,
652 &dev_attr_priority_queueing
.attr
,
653 &dev_attr_buffer_count
.attr
,
654 &dev_attr_recover
.attr
,
655 &dev_attr_performance_stats
.attr
,
656 &dev_attr_layer2
.attr
,
657 &dev_attr_isolation
.attr
,
658 &dev_attr_hw_trap
.attr
,
659 &dev_attr_switch_attrs
.attr
,
662 const struct attribute_group qeth_device_attr_group
= {
663 .attrs
= qeth_device_attrs
,
665 EXPORT_SYMBOL_GPL(qeth_device_attr_group
);
667 const struct attribute_group
*qeth_generic_attr_groups
[] = {
668 &qeth_device_attr_group
,
669 &qeth_device_blkt_group
,
673 static struct attribute
*qeth_osn_device_attrs
[] = {
674 &dev_attr_state
.attr
,
675 &dev_attr_chpid
.attr
,
676 &dev_attr_if_name
.attr
,
677 &dev_attr_card_type
.attr
,
678 &dev_attr_buffer_count
.attr
,
679 &dev_attr_recover
.attr
,
682 static struct attribute_group qeth_osn_device_attr_group
= {
683 .attrs
= qeth_osn_device_attrs
,
685 const struct attribute_group
*qeth_osn_attr_groups
[] = {
686 &qeth_osn_device_attr_group
,