2 * Copyright IBM Corp. 2007
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/list.h>
13 #include <linux/rwsem.h>
14 #include <asm/ebcdic.h>
16 #include "qeth_core.h"
18 static ssize_t
qeth_dev_state_show(struct device
*dev
,
19 struct device_attribute
*attr
, char *buf
)
21 struct qeth_card
*card
= dev_get_drvdata(dev
);
25 switch (card
->state
) {
27 return sprintf(buf
, "DOWN\n");
28 case CARD_STATE_HARDSETUP
:
29 return sprintf(buf
, "HARDSETUP\n");
30 case CARD_STATE_SOFTSETUP
:
31 return sprintf(buf
, "SOFTSETUP\n");
34 return sprintf(buf
, "UP (LAN ONLINE)\n");
36 return sprintf(buf
, "UP (LAN OFFLINE)\n");
37 case CARD_STATE_RECOVER
:
38 return sprintf(buf
, "RECOVER\n");
40 return sprintf(buf
, "UNKNOWN\n");
44 static DEVICE_ATTR(state
, 0444, qeth_dev_state_show
, NULL
);
46 static ssize_t
qeth_dev_chpid_show(struct device
*dev
,
47 struct device_attribute
*attr
, char *buf
)
49 struct qeth_card
*card
= dev_get_drvdata(dev
);
53 return sprintf(buf
, "%02X\n", card
->info
.chpid
);
56 static DEVICE_ATTR(chpid
, 0444, qeth_dev_chpid_show
, NULL
);
58 static ssize_t
qeth_dev_if_name_show(struct device
*dev
,
59 struct device_attribute
*attr
, char *buf
)
61 struct qeth_card
*card
= dev_get_drvdata(dev
);
64 return sprintf(buf
, "%s\n", QETH_CARD_IFNAME(card
));
67 static DEVICE_ATTR(if_name
, 0444, qeth_dev_if_name_show
, NULL
);
69 static ssize_t
qeth_dev_card_type_show(struct device
*dev
,
70 struct device_attribute
*attr
, char *buf
)
72 struct qeth_card
*card
= dev_get_drvdata(dev
);
76 return sprintf(buf
, "%s\n", qeth_get_cardname_short(card
));
79 static DEVICE_ATTR(card_type
, 0444, qeth_dev_card_type_show
, NULL
);
81 static inline const char *qeth_get_bufsize_str(struct qeth_card
*card
)
83 if (card
->qdio
.in_buf_size
== 16384)
85 else if (card
->qdio
.in_buf_size
== 24576)
87 else if (card
->qdio
.in_buf_size
== 32768)
89 else if (card
->qdio
.in_buf_size
== 40960)
95 static ssize_t
qeth_dev_inbuf_size_show(struct device
*dev
,
96 struct device_attribute
*attr
, char *buf
)
98 struct qeth_card
*card
= dev_get_drvdata(dev
);
102 return sprintf(buf
, "%s\n", qeth_get_bufsize_str(card
));
105 static DEVICE_ATTR(inbuf_size
, 0444, qeth_dev_inbuf_size_show
, NULL
);
107 static ssize_t
qeth_dev_portno_show(struct device
*dev
,
108 struct device_attribute
*attr
, char *buf
)
110 struct qeth_card
*card
= dev_get_drvdata(dev
);
114 return sprintf(buf
, "%i\n", card
->info
.portno
);
117 static ssize_t
qeth_dev_portno_store(struct device
*dev
,
118 struct device_attribute
*attr
, const char *buf
, size_t count
)
120 struct qeth_card
*card
= dev_get_drvdata(dev
);
122 unsigned int portno
, limit
;
128 mutex_lock(&card
->conf_mutex
);
129 if ((card
->state
!= CARD_STATE_DOWN
) &&
130 (card
->state
!= CARD_STATE_RECOVER
)) {
135 portno
= simple_strtoul(buf
, &tmp
, 16);
136 if (portno
> QETH_MAX_PORTNO
) {
140 limit
= (card
->ssqd
.pcnt
? card
->ssqd
.pcnt
- 1 : card
->ssqd
.pcnt
);
141 if (portno
> limit
) {
145 card
->info
.portno
= portno
;
147 mutex_unlock(&card
->conf_mutex
);
148 return rc
? rc
: count
;
151 static DEVICE_ATTR(portno
, 0644, qeth_dev_portno_show
, qeth_dev_portno_store
);
153 static ssize_t
qeth_dev_portname_show(struct device
*dev
,
154 struct device_attribute
*attr
, char *buf
)
156 struct qeth_card
*card
= dev_get_drvdata(dev
);
157 char portname
[9] = {0, };
162 if (card
->info
.portname_required
) {
163 memcpy(portname
, card
->info
.portname
+ 1, 8);
165 return sprintf(buf
, "%s\n", portname
);
167 return sprintf(buf
, "no portname required\n");
170 static ssize_t
qeth_dev_portname_store(struct device
*dev
,
171 struct device_attribute
*attr
, const char *buf
, size_t count
)
173 struct qeth_card
*card
= dev_get_drvdata(dev
);
180 mutex_lock(&card
->conf_mutex
);
181 if ((card
->state
!= CARD_STATE_DOWN
) &&
182 (card
->state
!= CARD_STATE_RECOVER
)) {
187 tmp
= strsep((char **) &buf
, "\n");
188 if ((strlen(tmp
) > 8) || (strlen(tmp
) == 0)) {
193 card
->info
.portname
[0] = strlen(tmp
);
194 /* for beauty reasons */
195 for (i
= 1; i
< 9; i
++)
196 card
->info
.portname
[i
] = ' ';
197 strcpy(card
->info
.portname
+ 1, tmp
);
198 ASCEBC(card
->info
.portname
+ 1, 8);
200 mutex_unlock(&card
->conf_mutex
);
201 return rc
? rc
: count
;
204 static DEVICE_ATTR(portname
, 0644, qeth_dev_portname_show
,
205 qeth_dev_portname_store
);
207 static ssize_t
qeth_dev_prioqing_show(struct device
*dev
,
208 struct device_attribute
*attr
, char *buf
)
210 struct qeth_card
*card
= dev_get_drvdata(dev
);
215 switch (card
->qdio
.do_prio_queueing
) {
216 case QETH_PRIO_Q_ING_PREC
:
217 return sprintf(buf
, "%s\n", "by precedence");
218 case QETH_PRIO_Q_ING_TOS
:
219 return sprintf(buf
, "%s\n", "by type of service");
221 return sprintf(buf
, "always queue %i\n",
222 card
->qdio
.default_out_queue
);
226 static ssize_t
qeth_dev_prioqing_store(struct device
*dev
,
227 struct device_attribute
*attr
, const char *buf
, size_t count
)
229 struct qeth_card
*card
= dev_get_drvdata(dev
);
236 mutex_lock(&card
->conf_mutex
);
237 if ((card
->state
!= CARD_STATE_DOWN
) &&
238 (card
->state
!= CARD_STATE_RECOVER
)) {
243 /* check if 1920 devices are supported ,
244 * if though we have to permit priority queueing
246 if (card
->qdio
.no_out_queues
== 1) {
247 card
->qdio
.do_prio_queueing
= QETH_PRIOQ_DEFAULT
;
252 tmp
= strsep((char **) &buf
, "\n");
253 if (!strcmp(tmp
, "prio_queueing_prec"))
254 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_PREC
;
255 else if (!strcmp(tmp
, "prio_queueing_tos"))
256 card
->qdio
.do_prio_queueing
= QETH_PRIO_Q_ING_TOS
;
257 else if (!strcmp(tmp
, "no_prio_queueing:0")) {
258 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
259 card
->qdio
.default_out_queue
= 0;
260 } else if (!strcmp(tmp
, "no_prio_queueing:1")) {
261 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
262 card
->qdio
.default_out_queue
= 1;
263 } else if (!strcmp(tmp
, "no_prio_queueing:2")) {
264 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
265 card
->qdio
.default_out_queue
= 2;
266 } else if (!strcmp(tmp
, "no_prio_queueing:3")) {
267 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
268 card
->qdio
.default_out_queue
= 3;
269 } else if (!strcmp(tmp
, "no_prio_queueing")) {
270 card
->qdio
.do_prio_queueing
= QETH_NO_PRIO_QUEUEING
;
271 card
->qdio
.default_out_queue
= QETH_DEFAULT_QUEUE
;
275 mutex_unlock(&card
->conf_mutex
);
276 return rc
? rc
: count
;
279 static DEVICE_ATTR(priority_queueing
, 0644, qeth_dev_prioqing_show
,
280 qeth_dev_prioqing_store
);
282 static ssize_t
qeth_dev_bufcnt_show(struct device
*dev
,
283 struct device_attribute
*attr
, char *buf
)
285 struct qeth_card
*card
= dev_get_drvdata(dev
);
290 return sprintf(buf
, "%i\n", card
->qdio
.in_buf_pool
.buf_count
);
293 static ssize_t
qeth_dev_bufcnt_store(struct device
*dev
,
294 struct device_attribute
*attr
, const char *buf
, size_t count
)
296 struct qeth_card
*card
= dev_get_drvdata(dev
);
304 mutex_lock(&card
->conf_mutex
);
305 if ((card
->state
!= CARD_STATE_DOWN
) &&
306 (card
->state
!= CARD_STATE_RECOVER
)) {
311 old_cnt
= card
->qdio
.in_buf_pool
.buf_count
;
312 cnt
= simple_strtoul(buf
, &tmp
, 10);
313 cnt
= (cnt
< QETH_IN_BUF_COUNT_MIN
) ? QETH_IN_BUF_COUNT_MIN
:
314 ((cnt
> QETH_IN_BUF_COUNT_MAX
) ? QETH_IN_BUF_COUNT_MAX
: cnt
);
315 if (old_cnt
!= cnt
) {
316 rc
= qeth_realloc_buffer_pool(card
, cnt
);
319 mutex_unlock(&card
->conf_mutex
);
320 return rc
? rc
: count
;
323 static DEVICE_ATTR(buffer_count
, 0644, qeth_dev_bufcnt_show
,
324 qeth_dev_bufcnt_store
);
326 static ssize_t
qeth_dev_recover_store(struct device
*dev
,
327 struct device_attribute
*attr
, const char *buf
, size_t count
)
329 struct qeth_card
*card
= dev_get_drvdata(dev
);
336 if (card
->state
!= CARD_STATE_UP
)
339 i
= simple_strtoul(buf
, &tmp
, 16);
341 qeth_schedule_recovery(card
);
346 static DEVICE_ATTR(recover
, 0200, NULL
, qeth_dev_recover_store
);
348 static ssize_t
qeth_dev_performance_stats_show(struct device
*dev
,
349 struct device_attribute
*attr
, char *buf
)
351 struct qeth_card
*card
= dev_get_drvdata(dev
);
356 return sprintf(buf
, "%i\n", card
->options
.performance_stats
? 1:0);
359 static ssize_t
qeth_dev_performance_stats_store(struct device
*dev
,
360 struct device_attribute
*attr
, const char *buf
, size_t count
)
362 struct qeth_card
*card
= dev_get_drvdata(dev
);
369 mutex_lock(&card
->conf_mutex
);
370 i
= simple_strtoul(buf
, &tmp
, 16);
371 if ((i
== 0) || (i
== 1)) {
372 if (i
== card
->options
.performance_stats
)
374 card
->options
.performance_stats
= i
;
376 memset(&card
->perf_stats
, 0,
377 sizeof(struct qeth_perf_stats
));
378 card
->perf_stats
.initial_rx_packets
= card
->stats
.rx_packets
;
379 card
->perf_stats
.initial_tx_packets
= card
->stats
.tx_packets
;
383 mutex_unlock(&card
->conf_mutex
);
384 return rc
? rc
: count
;
387 static DEVICE_ATTR(performance_stats
, 0644, qeth_dev_performance_stats_show
,
388 qeth_dev_performance_stats_store
);
390 static ssize_t
qeth_dev_layer2_show(struct device
*dev
,
391 struct device_attribute
*attr
, char *buf
)
393 struct qeth_card
*card
= dev_get_drvdata(dev
);
398 return sprintf(buf
, "%i\n", card
->options
.layer2
);
401 static ssize_t
qeth_dev_layer2_store(struct device
*dev
,
402 struct device_attribute
*attr
, const char *buf
, size_t count
)
404 struct qeth_card
*card
= dev_get_drvdata(dev
);
407 enum qeth_discipline_id newdis
;
412 mutex_lock(&card
->discipline_mutex
);
413 if (card
->state
!= CARD_STATE_DOWN
) {
418 i
= simple_strtoul(buf
, &tmp
, 16);
421 newdis
= QETH_DISCIPLINE_LAYER3
;
424 newdis
= QETH_DISCIPLINE_LAYER2
;
431 if (card
->options
.layer2
== newdis
)
434 card
->info
.mac_bits
= 0;
435 if (card
->discipline
) {
436 card
->discipline
->remove(card
->gdev
);
437 qeth_core_free_discipline(card
);
441 rc
= qeth_core_load_discipline(card
, newdis
);
445 rc
= card
->discipline
->setup(card
->gdev
);
447 mutex_unlock(&card
->discipline_mutex
);
448 return rc
? rc
: count
;
451 static DEVICE_ATTR(layer2
, 0644, qeth_dev_layer2_show
,
452 qeth_dev_layer2_store
);
454 #define ATTR_QETH_ISOLATION_NONE ("none")
455 #define ATTR_QETH_ISOLATION_FWD ("forward")
456 #define ATTR_QETH_ISOLATION_DROP ("drop")
458 static ssize_t
qeth_dev_isolation_show(struct device
*dev
,
459 struct device_attribute
*attr
, char *buf
)
461 struct qeth_card
*card
= dev_get_drvdata(dev
);
466 switch (card
->options
.isolation
) {
467 case ISOLATION_MODE_NONE
:
468 return snprintf(buf
, 6, "%s\n", ATTR_QETH_ISOLATION_NONE
);
469 case ISOLATION_MODE_FWD
:
470 return snprintf(buf
, 9, "%s\n", ATTR_QETH_ISOLATION_FWD
);
471 case ISOLATION_MODE_DROP
:
472 return snprintf(buf
, 6, "%s\n", ATTR_QETH_ISOLATION_DROP
);
474 return snprintf(buf
, 5, "%s\n", "N/A");
478 static ssize_t
qeth_dev_isolation_store(struct device
*dev
,
479 struct device_attribute
*attr
, const char *buf
, size_t count
)
481 struct qeth_card
*card
= dev_get_drvdata(dev
);
482 enum qeth_ipa_isolation_modes isolation
;
484 char *tmp
, *curtoken
;
485 curtoken
= (char *) buf
;
490 mutex_lock(&card
->conf_mutex
);
491 /* check for unknown, too, in case we do not yet know who we are */
492 if (card
->info
.type
!= QETH_CARD_TYPE_OSD
&&
493 card
->info
.type
!= QETH_CARD_TYPE_OSX
&&
494 card
->info
.type
!= QETH_CARD_TYPE_UNKNOWN
) {
496 dev_err(&card
->gdev
->dev
, "Adapter does not "
497 "support QDIO data connection isolation\n");
501 /* parse input into isolation mode */
502 tmp
= strsep(&curtoken
, "\n");
503 if (!strcmp(tmp
, ATTR_QETH_ISOLATION_NONE
)) {
504 isolation
= ISOLATION_MODE_NONE
;
505 } else if (!strcmp(tmp
, ATTR_QETH_ISOLATION_FWD
)) {
506 isolation
= ISOLATION_MODE_FWD
;
507 } else if (!strcmp(tmp
, ATTR_QETH_ISOLATION_DROP
)) {
508 isolation
= ISOLATION_MODE_DROP
;
515 /* defer IP assist if device is offline (until discipline->set_online)*/
516 card
->options
.prev_isolation
= card
->options
.isolation
;
517 card
->options
.isolation
= isolation
;
518 if (card
->state
== CARD_STATE_SOFTSETUP
||
519 card
->state
== CARD_STATE_UP
) {
520 int ipa_rc
= qeth_set_access_ctrl_online(card
, 1);
525 mutex_unlock(&card
->conf_mutex
);
529 static DEVICE_ATTR(isolation
, 0644, qeth_dev_isolation_show
,
530 qeth_dev_isolation_store
);
532 static ssize_t
qeth_hw_trap_show(struct device
*dev
,
533 struct device_attribute
*attr
, char *buf
)
535 struct qeth_card
*card
= dev_get_drvdata(dev
);
539 if (card
->info
.hwtrap
)
540 return snprintf(buf
, 5, "arm\n");
542 return snprintf(buf
, 8, "disarm\n");
545 static ssize_t
qeth_hw_trap_store(struct device
*dev
,
546 struct device_attribute
*attr
, const char *buf
, size_t count
)
548 struct qeth_card
*card
= dev_get_drvdata(dev
);
550 char *tmp
, *curtoken
;
552 curtoken
= (char *)buf
;
557 mutex_lock(&card
->conf_mutex
);
558 if (card
->state
== CARD_STATE_SOFTSETUP
|| card
->state
== CARD_STATE_UP
)
560 tmp
= strsep(&curtoken
, "\n");
562 if (!strcmp(tmp
, "arm") && !card
->info
.hwtrap
) {
564 if (qeth_is_diagass_supported(card
,
565 QETH_DIAGS_CMD_TRAP
)) {
566 rc
= qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
);
568 card
->info
.hwtrap
= 1;
572 card
->info
.hwtrap
= 1;
573 } else if (!strcmp(tmp
, "disarm") && card
->info
.hwtrap
) {
575 rc
= qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
577 card
->info
.hwtrap
= 0;
579 card
->info
.hwtrap
= 0;
580 } else if (!strcmp(tmp
, "trap") && state
&& card
->info
.hwtrap
)
581 rc
= qeth_hw_trap(card
, QETH_DIAGS_TRAP_CAPTURE
);
585 mutex_unlock(&card
->conf_mutex
);
586 return rc
? rc
: count
;
589 static DEVICE_ATTR(hw_trap
, 0644, qeth_hw_trap_show
,
592 static ssize_t
qeth_dev_blkt_show(char *buf
, struct qeth_card
*card
, int value
)
598 return sprintf(buf
, "%i\n", value
);
601 static ssize_t
qeth_dev_blkt_store(struct qeth_card
*card
,
602 const char *buf
, size_t count
, int *value
, int max_value
)
610 mutex_lock(&card
->conf_mutex
);
611 if ((card
->state
!= CARD_STATE_DOWN
) &&
612 (card
->state
!= CARD_STATE_RECOVER
)) {
616 i
= simple_strtoul(buf
, &tmp
, 10);
622 mutex_unlock(&card
->conf_mutex
);
623 return rc
? rc
: count
;
626 static ssize_t
qeth_dev_blkt_total_show(struct device
*dev
,
627 struct device_attribute
*attr
, char *buf
)
629 struct qeth_card
*card
= dev_get_drvdata(dev
);
631 return qeth_dev_blkt_show(buf
, card
, card
->info
.blkt
.time_total
);
634 static ssize_t
qeth_dev_blkt_total_store(struct device
*dev
,
635 struct device_attribute
*attr
, const char *buf
, size_t count
)
637 struct qeth_card
*card
= dev_get_drvdata(dev
);
639 return qeth_dev_blkt_store(card
, buf
, count
,
640 &card
->info
.blkt
.time_total
, 5000);
645 static DEVICE_ATTR(total
, 0644, qeth_dev_blkt_total_show
,
646 qeth_dev_blkt_total_store
);
648 static ssize_t
qeth_dev_blkt_inter_show(struct device
*dev
,
649 struct device_attribute
*attr
, char *buf
)
651 struct qeth_card
*card
= dev_get_drvdata(dev
);
653 return qeth_dev_blkt_show(buf
, card
, card
->info
.blkt
.inter_packet
);
656 static ssize_t
qeth_dev_blkt_inter_store(struct device
*dev
,
657 struct device_attribute
*attr
, const char *buf
, size_t count
)
659 struct qeth_card
*card
= dev_get_drvdata(dev
);
661 return qeth_dev_blkt_store(card
, buf
, count
,
662 &card
->info
.blkt
.inter_packet
, 1000);
665 static DEVICE_ATTR(inter
, 0644, qeth_dev_blkt_inter_show
,
666 qeth_dev_blkt_inter_store
);
668 static ssize_t
qeth_dev_blkt_inter_jumbo_show(struct device
*dev
,
669 struct device_attribute
*attr
, char *buf
)
671 struct qeth_card
*card
= dev_get_drvdata(dev
);
673 return qeth_dev_blkt_show(buf
, card
,
674 card
->info
.blkt
.inter_packet_jumbo
);
677 static ssize_t
qeth_dev_blkt_inter_jumbo_store(struct device
*dev
,
678 struct device_attribute
*attr
, const char *buf
, size_t count
)
680 struct qeth_card
*card
= dev_get_drvdata(dev
);
682 return qeth_dev_blkt_store(card
, buf
, count
,
683 &card
->info
.blkt
.inter_packet_jumbo
, 1000);
686 static DEVICE_ATTR(inter_jumbo
, 0644, qeth_dev_blkt_inter_jumbo_show
,
687 qeth_dev_blkt_inter_jumbo_store
);
689 static struct attribute
*qeth_blkt_device_attrs
[] = {
690 &dev_attr_total
.attr
,
691 &dev_attr_inter
.attr
,
692 &dev_attr_inter_jumbo
.attr
,
695 static struct attribute_group qeth_device_blkt_group
= {
697 .attrs
= qeth_blkt_device_attrs
,
700 static struct attribute
*qeth_device_attrs
[] = {
701 &dev_attr_state
.attr
,
702 &dev_attr_chpid
.attr
,
703 &dev_attr_if_name
.attr
,
704 &dev_attr_card_type
.attr
,
705 &dev_attr_inbuf_size
.attr
,
706 &dev_attr_portno
.attr
,
707 &dev_attr_portname
.attr
,
708 &dev_attr_priority_queueing
.attr
,
709 &dev_attr_buffer_count
.attr
,
710 &dev_attr_recover
.attr
,
711 &dev_attr_performance_stats
.attr
,
712 &dev_attr_layer2
.attr
,
713 &dev_attr_isolation
.attr
,
714 &dev_attr_hw_trap
.attr
,
717 static struct attribute_group qeth_device_attr_group
= {
718 .attrs
= qeth_device_attrs
,
721 const struct attribute_group
*qeth_generic_attr_groups
[] = {
722 &qeth_device_attr_group
,
723 &qeth_device_blkt_group
,
727 static struct attribute
*qeth_osn_device_attrs
[] = {
728 &dev_attr_state
.attr
,
729 &dev_attr_chpid
.attr
,
730 &dev_attr_if_name
.attr
,
731 &dev_attr_card_type
.attr
,
732 &dev_attr_buffer_count
.attr
,
733 &dev_attr_recover
.attr
,
736 static struct attribute_group qeth_osn_device_attr_group
= {
737 .attrs
= qeth_osn_device_attrs
,
739 const struct attribute_group
*qeth_osn_attr_groups
[] = {
740 &qeth_osn_device_attr_group
,