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");
220 case QETH_PRIO_Q_ING_SKB:
221 return sprintf(buf, "%s\n", "by skb-priority");
222 case QETH_PRIO_Q_ING_VLAN:
223 return sprintf(buf, "%s\n", "by VLAN headers");
225 return sprintf(buf, "always queue %i\n",
226 card->qdio.default_out_queue);
230 static ssize_t qeth_dev_prioqing_store(struct device *dev,
231 struct device_attribute *attr, const char *buf, size_t count)
233 struct qeth_card *card = dev_get_drvdata(dev);
240 mutex_lock(&card->conf_mutex);
241 if ((card->state != CARD_STATE_DOWN) &&
242 (card->state != CARD_STATE_RECOVER)) {
247 /* check if 1920 devices are supported ,
248 * if though we have to permit priority queueing
250 if (card->qdio.no_out_queues == 1) {
251 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
256 tmp = strsep((char **) &buf, "\n");
257 if (!strcmp(tmp, "prio_queueing_prec")) {
258 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
259 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
260 } else if (!strcmp(tmp, "prio_queueing_skb")) {
261 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_SKB;
262 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
263 } else if (!strcmp(tmp, "prio_queueing_tos")) {
264 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
265 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
266 } else if (!strcmp(tmp, "prio_queueing_vlan")) {
267 if (!card->options.layer2) {
271 card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_VLAN;
272 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
273 } else if (!strcmp(tmp, "no_prio_queueing:0")) {
274 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
275 card->qdio.default_out_queue = 0;
276 } else if (!strcmp(tmp, "no_prio_queueing:1")) {
277 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
278 card->qdio.default_out_queue = 1;
279 } else if (!strcmp(tmp, "no_prio_queueing:2")) {
280 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
281 card->qdio.default_out_queue = 2;
282 } else if (!strcmp(tmp, "no_prio_queueing:3")) {
283 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
284 card->qdio.default_out_queue = 3;
285 } else if (!strcmp(tmp, "no_prio_queueing")) {
286 card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
287 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
291 mutex_unlock(&card->conf_mutex);
292 return rc ? rc : count;
295 static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
296 qeth_dev_prioqing_store);
298 static ssize_t qeth_dev_bufcnt_show(struct device *dev,
299 struct device_attribute *attr, char *buf)
301 struct qeth_card *card = dev_get_drvdata(dev);
306 return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
309 static ssize_t qeth_dev_bufcnt_store(struct device *dev,
310 struct device_attribute *attr, const char *buf, size_t count)
312 struct qeth_card *card = dev_get_drvdata(dev);
320 mutex_lock(&card->conf_mutex);
321 if ((card->state != CARD_STATE_DOWN) &&
322 (card->state != CARD_STATE_RECOVER)) {
327 old_cnt = card->qdio.in_buf_pool.buf_count;
328 cnt = simple_strtoul(buf, &tmp, 10);
329 cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
330 ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
331 if (old_cnt != cnt) {
332 rc = qeth_realloc_buffer_pool(card, cnt);
335 mutex_unlock(&card->conf_mutex);
336 return rc ? rc : count;
339 static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
340 qeth_dev_bufcnt_store);
342 static ssize_t qeth_dev_recover_store(struct device *dev,
343 struct device_attribute *attr, const char *buf, size_t count)
345 struct qeth_card *card = dev_get_drvdata(dev);
352 if (card->state != CARD_STATE_UP)
355 i = simple_strtoul(buf, &tmp, 16);
357 qeth_schedule_recovery(card);
362 static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
364 static ssize_t qeth_dev_performance_stats_show(struct device *dev,
365 struct device_attribute *attr, char *buf)
367 struct qeth_card *card = dev_get_drvdata(dev);
372 return sprintf(buf, "%i\n", card->options.performance_stats ? 1:0);
375 static ssize_t qeth_dev_performance_stats_store(struct device *dev,
376 struct device_attribute *attr, const char *buf, size_t count)
378 struct qeth_card *card = dev_get_drvdata(dev);
385 mutex_lock(&card->conf_mutex);
386 i = simple_strtoul(buf, &tmp, 16);
387 if ((i == 0) || (i == 1)) {
388 if (i == card->options.performance_stats)
390 card->options.performance_stats = i;
392 memset(&card->perf_stats, 0,
393 sizeof(struct qeth_perf_stats));
394 card->perf_stats.initial_rx_packets = card->stats.rx_packets;
395 card->perf_stats.initial_tx_packets = card->stats.tx_packets;
399 mutex_unlock(&card->conf_mutex);
400 return rc ? rc : count;
403 static DEVICE_ATTR(performance_stats, 0644, qeth_dev_performance_stats_show,
404 qeth_dev_performance_stats_store);
406 static ssize_t qeth_dev_layer2_show(struct device *dev,
407 struct device_attribute *attr, char *buf)
409 struct qeth_card *card = dev_get_drvdata(dev);
414 return sprintf(buf, "%i\n", card->options.layer2);
417 static ssize_t qeth_dev_layer2_store(struct device *dev,
418 struct device_attribute *attr, const char *buf, size_t count)
420 struct qeth_card *card = dev_get_drvdata(dev);
423 enum qeth_discipline_id newdis;
428 mutex_lock(&card->discipline_mutex);
429 if (card->state != CARD_STATE_DOWN) {
434 i = simple_strtoul(buf, &tmp, 16);
437 newdis = QETH_DISCIPLINE_LAYER3;
440 newdis = QETH_DISCIPLINE_LAYER2;
447 if (card->options.layer2 == newdis)
450 card->info.mac_bits = 0;
451 if (card->discipline) {
452 card->discipline->remove(card->gdev);
453 qeth_core_free_discipline(card);
457 rc = qeth_core_load_discipline(card, newdis);
461 rc = card->discipline->setup(card->gdev);
463 mutex_unlock(&card->discipline_mutex);
464 return rc ? rc : count;
467 static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
468 qeth_dev_layer2_store);
470 #define ATTR_QETH_ISOLATION_NONE ("none")
471 #define ATTR_QETH_ISOLATION_FWD ("forward")
472 #define ATTR_QETH_ISOLATION_DROP ("drop")
474 static ssize_t qeth_dev_isolation_show(struct device *dev,
475 struct device_attribute *attr, char *buf)
477 struct qeth_card *card = dev_get_drvdata(dev);
482 switch (card->options.isolation) {
483 case ISOLATION_MODE_NONE:
484 return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_NONE);
485 case ISOLATION_MODE_FWD:
486 return snprintf(buf, 9, "%s\n", ATTR_QETH_ISOLATION_FWD);
487 case ISOLATION_MODE_DROP:
488 return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_DROP);
490 return snprintf(buf, 5, "%s\n", "N/A");
494 static ssize_t qeth_dev_isolation_store(struct device *dev,
495 struct device_attribute *attr, const char *buf, size_t count)
497 struct qeth_card *card = dev_get_drvdata(dev);
498 enum qeth_ipa_isolation_modes isolation;
500 char *tmp, *curtoken;
501 curtoken = (char *) buf;
506 mutex_lock(&card->conf_mutex);
507 /* check for unknown, too, in case we do not yet know who we are */
508 if (card->info.type != QETH_CARD_TYPE_OSD &&
509 card->info.type != QETH_CARD_TYPE_OSX &&
510 card->info.type != QETH_CARD_TYPE_UNKNOWN) {
512 dev_err(&card->gdev->dev, "Adapter does not "
513 "support QDIO data connection isolation\n");
517 /* parse input into isolation mode */
518 tmp = strsep(&curtoken, "\n");
519 if (!strcmp(tmp, ATTR_QETH_ISOLATION_NONE)) {
520 isolation = ISOLATION_MODE_NONE;
521 } else if (!strcmp(tmp, ATTR_QETH_ISOLATION_FWD)) {
522 isolation = ISOLATION_MODE_FWD;
523 } else if (!strcmp(tmp, ATTR_QETH_ISOLATION_DROP)) {
524 isolation = ISOLATION_MODE_DROP;
531 /* defer IP assist if device is offline (until discipline->set_online)*/
532 card->options.prev_isolation = card->options.isolation;
533 card->options.isolation = isolation;
534 if (card->state == CARD_STATE_SOFTSETUP ||
535 card->state == CARD_STATE_UP) {
536 int ipa_rc = qeth_set_access_ctrl_online(card, 1);
541 mutex_unlock(&card->conf_mutex);
545 static DEVICE_ATTR(isolation, 0644, qeth_dev_isolation_show,
546 qeth_dev_isolation_store);
548 static ssize_t qeth_hw_trap_show(struct device *dev,
549 struct device_attribute *attr, char *buf)
551 struct qeth_card *card = dev_get_drvdata(dev);
555 if (card->info.hwtrap)
556 return snprintf(buf, 5, "arm\n");
558 return snprintf(buf, 8, "disarm\n");
561 static ssize_t qeth_hw_trap_store(struct device *dev,
562 struct device_attribute *attr, const char *buf, size_t count)
564 struct qeth_card *card = dev_get_drvdata(dev);
566 char *tmp, *curtoken;
568 curtoken = (char *)buf;
573 mutex_lock(&card->conf_mutex);
574 if (card->state == CARD_STATE_SOFTSETUP || card->state == CARD_STATE_UP)
576 tmp = strsep(&curtoken, "\n");
578 if (!strcmp(tmp, "arm") && !card->info.hwtrap) {
580 if (qeth_is_diagass_supported(card,
581 QETH_DIAGS_CMD_TRAP)) {
582 rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM);
584 card->info.hwtrap = 1;
588 card->info.hwtrap = 1;
589 } else if (!strcmp(tmp, "disarm") && card->info.hwtrap) {
591 rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
593 card->info.hwtrap = 0;
595 card->info.hwtrap = 0;
596 } else if (!strcmp(tmp, "trap") && state && card->info.hwtrap)
597 rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_CAPTURE);
601 mutex_unlock(&card->conf_mutex);
602 return rc ? rc : count;
605 static DEVICE_ATTR(hw_trap, 0644, qeth_hw_trap_show,
608 static ssize_t qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value)
614 return sprintf(buf, "%i\n", value);
617 static ssize_t qeth_dev_blkt_store(struct qeth_card *card,
618 const char *buf, size_t count, int *value, int max_value)
626 mutex_lock(&card->conf_mutex);
627 if ((card->state != CARD_STATE_DOWN) &&
628 (card->state != CARD_STATE_RECOVER)) {
632 i = simple_strtoul(buf, &tmp, 10);
638 mutex_unlock(&card->conf_mutex);
639 return rc ? rc : count;
642 static ssize_t qeth_dev_blkt_total_show(struct device *dev,
643 struct device_attribute *attr, char *buf)
645 struct qeth_card *card = dev_get_drvdata(dev);
647 return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
650 static ssize_t qeth_dev_blkt_total_store(struct device *dev,
651 struct device_attribute *attr, const char *buf, size_t count)
653 struct qeth_card *card = dev_get_drvdata(dev);
655 return qeth_dev_blkt_store(card, buf, count,
656 &card->info.blkt.time_total, 5000);
661 static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
662 qeth_dev_blkt_total_store);
664 static ssize_t qeth_dev_blkt_inter_show(struct device *dev,
665 struct device_attribute *attr, char *buf)
667 struct qeth_card *card = dev_get_drvdata(dev);
669 return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
672 static ssize_t qeth_dev_blkt_inter_store(struct device *dev,
673 struct device_attribute *attr, const char *buf, size_t count)
675 struct qeth_card *card = dev_get_drvdata(dev);
677 return qeth_dev_blkt_store(card, buf, count,
678 &card->info.blkt.inter_packet, 1000);
681 static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
682 qeth_dev_blkt_inter_store);
684 static ssize_t qeth_dev_blkt_inter_jumbo_show(struct device *dev,
685 struct device_attribute *attr, char *buf)
687 struct qeth_card *card = dev_get_drvdata(dev);
689 return qeth_dev_blkt_show(buf, card,
690 card->info.blkt.inter_packet_jumbo);
693 static ssize_t qeth_dev_blkt_inter_jumbo_store(struct device *dev,
694 struct device_attribute *attr, const char *buf, size_t count)
696 struct qeth_card *card = dev_get_drvdata(dev);
698 return qeth_dev_blkt_store(card, buf, count,
699 &card->info.blkt.inter_packet_jumbo, 1000);
702 static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
703 qeth_dev_blkt_inter_jumbo_store);
705 static struct attribute *qeth_blkt_device_attrs[] = {
706 &dev_attr_total.attr,
707 &dev_attr_inter.attr,
708 &dev_attr_inter_jumbo.attr,
711 static struct attribute_group qeth_device_blkt_group = {
713 .attrs = qeth_blkt_device_attrs,
716 static struct attribute *qeth_device_attrs[] = {
717 &dev_attr_state.attr,
718 &dev_attr_chpid.attr,
719 &dev_attr_if_name.attr,
720 &dev_attr_card_type.attr,
721 &dev_attr_inbuf_size.attr,
722 &dev_attr_portno.attr,
723 &dev_attr_portname.attr,
724 &dev_attr_priority_queueing.attr,
725 &dev_attr_buffer_count.attr,
726 &dev_attr_recover.attr,
727 &dev_attr_performance_stats.attr,
728 &dev_attr_layer2.attr,
729 &dev_attr_isolation.attr,
730 &dev_attr_hw_trap.attr,
733 static struct attribute_group qeth_device_attr_group = {
734 .attrs = qeth_device_attrs,
737 const struct attribute_group *qeth_generic_attr_groups[] = {
738 &qeth_device_attr_group,
739 &qeth_device_blkt_group,
743 static struct attribute *qeth_osn_device_attrs[] = {
744 &dev_attr_state.attr,
745 &dev_attr_chpid.attr,
746 &dev_attr_if_name.attr,
747 &dev_attr_card_type.attr,
748 &dev_attr_buffer_count.attr,
749 &dev_attr_recover.attr,
752 static struct attribute_group qeth_osn_device_attr_group = {
753 .attrs = qeth_osn_device_attrs,
755 const struct attribute_group *qeth_osn_attr_groups[] = {
756 &qeth_osn_device_attr_group,