WIP FPC-III support
[linux/fpc-iii.git] / drivers / s390 / net / qeth_core_sys.c
bloba0f777f76f66eec1cc322417185c33e841cab1f3
1 // SPDX-License-Identifier: GPL-2.0
2 /*
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>
8 */
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) {
25 case CARD_STATE_DOWN:
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" :
31 "OFFLINE");
32 return sprintf(buf, "SOFTSETUP\n");
33 default:
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", 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 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)
73 return "16k";
74 else if (card->qdio.in_buf_size == 24576)
75 return "24k";
76 else if (card->qdio.in_buf_size == 32768)
77 return "32k";
78 else if (card->qdio.in_buf_size == 40960)
79 return "40k";
80 else
81 return "64k";
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);
106 unsigned int portno, limit;
107 int rc = 0;
109 rc = kstrtouint(buf, 16, &portno);
110 if (rc)
111 return rc;
112 if (portno > QETH_MAX_PORTNO)
113 return -EINVAL;
115 mutex_lock(&card->conf_mutex);
116 if (card->state != CARD_STATE_DOWN) {
117 rc = -EPERM;
118 goto out;
121 limit = (card->ssqd.pcnt ? card->ssqd.pcnt - 1 : card->ssqd.pcnt);
122 if (portno > limit) {
123 rc = -EINVAL;
124 goto out;
126 card->dev->dev_port = portno;
127 out:
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");
147 return count;
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");
167 case QETH_PRIO_Q_ING_FIXED:
168 return sprintf(buf, "always queue %i\n",
169 card->qdio.default_out_queue);
170 default:
171 return sprintf(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);
179 int rc = 0;
181 if (IS_IQD(card) || IS_VM_NIC(card))
182 return -EOPNOTSUPP;
184 mutex_lock(&card->conf_mutex);
185 if (card->state != CARD_STATE_DOWN) {
186 rc = -EPERM;
187 goto out;
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;
195 rc = -EPERM;
196 goto out;
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)) {
210 rc = -EOPNOTSUPP;
211 goto out;
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;
230 } else
231 rc = -EINVAL;
232 out:
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 sprintf(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);
252 unsigned int cnt;
253 int rc = 0;
255 rc = kstrtouint(buf, 10, &cnt);
256 if (rc)
257 return rc;
259 mutex_lock(&card->conf_mutex);
260 if (card->state != CARD_STATE_DOWN) {
261 rc = -EPERM;
262 goto out;
265 cnt = clamp(cnt, QETH_IN_BUF_COUNT_MIN, QETH_IN_BUF_COUNT_MAX);
266 rc = qeth_resize_buffer_pool(card, cnt);
268 out:
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);
280 bool reset;
281 int rc;
283 rc = kstrtobool(buf, &reset);
284 if (rc)
285 return rc;
287 if (!qeth_card_hw_is_reachable(card))
288 return -EPERM;
290 if (reset)
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 sprintf(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;
309 unsigned int i;
310 bool reset;
311 int rc;
313 rc = kstrtobool(buf, &reset);
314 if (rc)
315 return rc;
317 if (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];
321 if (!queue)
322 break;
323 memset(&queue->stats, 0, sizeof(queue->stats));
327 return count;
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 sprintf(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;
347 unsigned int input;
348 int rc;
350 rc = kstrtouint(buf, 16, &input);
351 if (rc)
352 return rc;
354 switch (input) {
355 case 0:
356 newdis = QETH_DISCIPLINE_LAYER3;
357 break;
358 case 1:
359 newdis = QETH_DISCIPLINE_LAYER2;
360 break;
361 default:
362 return -EINVAL;
365 mutex_lock(&card->discipline_mutex);
366 if (card->state != CARD_STATE_DOWN) {
367 rc = -EPERM;
368 goto out;
371 if (card->options.layer == newdis)
372 goto out;
373 if (card->info.layer_enforced) {
374 /* fixed layer, can't switch */
375 rc = -EOPNOTSUPP;
376 goto out;
379 if (card->discipline) {
380 /* start with a new, pristine netdevice: */
381 ndev = qeth_clone_netdev(card->dev);
382 if (!ndev) {
383 rc = -ENOMEM;
384 goto out;
387 card->discipline->remove(card->gdev);
388 qeth_core_free_discipline(card);
389 free_netdev(card->dev);
390 card->dev = ndev;
393 rc = qeth_core_load_discipline(card, newdis);
394 if (rc)
395 goto out;
397 rc = card->discipline->setup(card->gdev);
398 if (rc)
399 qeth_core_free_discipline(card);
400 out:
401 mutex_unlock(&card->discipline_mutex);
402 return rc ? rc : count;
405 static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
406 qeth_dev_layer2_store);
408 #define ATTR_QETH_ISOLATION_NONE ("none")
409 #define ATTR_QETH_ISOLATION_FWD ("forward")
410 #define ATTR_QETH_ISOLATION_DROP ("drop")
412 static ssize_t qeth_dev_isolation_show(struct device *dev,
413 struct device_attribute *attr, char *buf)
415 struct qeth_card *card = dev_get_drvdata(dev);
417 switch (card->options.isolation) {
418 case ISOLATION_MODE_NONE:
419 return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_NONE);
420 case ISOLATION_MODE_FWD:
421 return snprintf(buf, 9, "%s\n", ATTR_QETH_ISOLATION_FWD);
422 case ISOLATION_MODE_DROP:
423 return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_DROP);
424 default:
425 return snprintf(buf, 5, "%s\n", "N/A");
429 static ssize_t qeth_dev_isolation_store(struct device *dev,
430 struct device_attribute *attr, const char *buf, size_t count)
432 struct qeth_card *card = dev_get_drvdata(dev);
433 enum qeth_ipa_isolation_modes isolation;
434 int rc = 0;
436 mutex_lock(&card->conf_mutex);
437 if (!IS_OSD(card) && !IS_OSX(card)) {
438 rc = -EOPNOTSUPP;
439 dev_err(&card->gdev->dev, "Adapter does not "
440 "support QDIO data connection isolation\n");
441 goto out;
444 /* parse input into isolation mode */
445 if (sysfs_streq(buf, ATTR_QETH_ISOLATION_NONE)) {
446 isolation = ISOLATION_MODE_NONE;
447 } else if (sysfs_streq(buf, ATTR_QETH_ISOLATION_FWD)) {
448 isolation = ISOLATION_MODE_FWD;
449 } else if (sysfs_streq(buf, ATTR_QETH_ISOLATION_DROP)) {
450 isolation = ISOLATION_MODE_DROP;
451 } else {
452 rc = -EINVAL;
453 goto out;
456 if (qeth_card_hw_is_reachable(card))
457 rc = qeth_setadpparms_set_access_ctrl(card, isolation);
459 if (!rc)
460 WRITE_ONCE(card->options.isolation, isolation);
462 out:
463 mutex_unlock(&card->conf_mutex);
465 return rc ? rc : count;
468 static DEVICE_ATTR(isolation, 0644, qeth_dev_isolation_show,
469 qeth_dev_isolation_store);
471 static ssize_t qeth_dev_switch_attrs_show(struct device *dev,
472 struct device_attribute *attr, char *buf)
474 struct qeth_card *card = dev_get_drvdata(dev);
475 struct qeth_switch_info sw_info;
476 int rc = 0;
478 if (!qeth_card_hw_is_reachable(card))
479 return sprintf(buf, "n/a\n");
481 rc = qeth_query_switch_attributes(card, &sw_info);
482 if (rc)
483 return rc;
485 if (!sw_info.capabilities)
486 rc = sprintf(buf, "unknown");
488 if (sw_info.capabilities & QETH_SWITCH_FORW_802_1)
489 rc = sprintf(buf, (sw_info.settings & QETH_SWITCH_FORW_802_1 ?
490 "[802.1]" : "802.1"));
491 if (sw_info.capabilities & QETH_SWITCH_FORW_REFL_RELAY)
492 rc += sprintf(buf + rc,
493 (sw_info.settings & QETH_SWITCH_FORW_REFL_RELAY ?
494 " [rr]" : " rr"));
495 rc += sprintf(buf + rc, "\n");
497 return rc;
500 static DEVICE_ATTR(switch_attrs, 0444,
501 qeth_dev_switch_attrs_show, NULL);
503 static ssize_t qeth_hw_trap_show(struct device *dev,
504 struct device_attribute *attr, char *buf)
506 struct qeth_card *card = dev_get_drvdata(dev);
508 if (card->info.hwtrap)
509 return snprintf(buf, 5, "arm\n");
510 else
511 return snprintf(buf, 8, "disarm\n");
514 static ssize_t qeth_hw_trap_store(struct device *dev,
515 struct device_attribute *attr, const char *buf, size_t count)
517 struct qeth_card *card = dev_get_drvdata(dev);
518 int rc = 0;
519 int state = 0;
521 mutex_lock(&card->conf_mutex);
522 if (qeth_card_hw_is_reachable(card))
523 state = 1;
525 if (sysfs_streq(buf, "arm") && !card->info.hwtrap) {
526 if (state) {
527 if (qeth_is_diagass_supported(card,
528 QETH_DIAGS_CMD_TRAP)) {
529 rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM);
530 if (!rc)
531 card->info.hwtrap = 1;
532 } else
533 rc = -EINVAL;
534 } else
535 card->info.hwtrap = 1;
536 } else if (sysfs_streq(buf, "disarm") && card->info.hwtrap) {
537 if (state) {
538 rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
539 if (!rc)
540 card->info.hwtrap = 0;
541 } else
542 card->info.hwtrap = 0;
543 } else if (sysfs_streq(buf, "trap") && state && card->info.hwtrap)
544 rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_CAPTURE);
545 else
546 rc = -EINVAL;
548 mutex_unlock(&card->conf_mutex);
549 return rc ? rc : count;
552 static DEVICE_ATTR(hw_trap, 0644, qeth_hw_trap_show,
553 qeth_hw_trap_store);
555 static ssize_t qeth_dev_blkt_store(struct qeth_card *card,
556 const char *buf, size_t count, int *value, int max_value)
558 unsigned int input;
559 int rc;
561 rc = kstrtouint(buf, 10, &input);
562 if (rc)
563 return rc;
565 if (input > max_value)
566 return -EINVAL;
568 mutex_lock(&card->conf_mutex);
569 if (card->state != CARD_STATE_DOWN)
570 rc = -EPERM;
571 else
572 *value = input;
573 mutex_unlock(&card->conf_mutex);
574 return rc ? rc : count;
577 static ssize_t qeth_dev_blkt_total_show(struct device *dev,
578 struct device_attribute *attr, char *buf)
580 struct qeth_card *card = dev_get_drvdata(dev);
582 return sprintf(buf, "%i\n", card->info.blkt.time_total);
585 static ssize_t qeth_dev_blkt_total_store(struct device *dev,
586 struct device_attribute *attr, const char *buf, size_t count)
588 struct qeth_card *card = dev_get_drvdata(dev);
590 return qeth_dev_blkt_store(card, buf, count,
591 &card->info.blkt.time_total, 5000);
594 static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
595 qeth_dev_blkt_total_store);
597 static ssize_t qeth_dev_blkt_inter_show(struct device *dev,
598 struct device_attribute *attr, char *buf)
600 struct qeth_card *card = dev_get_drvdata(dev);
602 return sprintf(buf, "%i\n", card->info.blkt.inter_packet);
605 static ssize_t qeth_dev_blkt_inter_store(struct device *dev,
606 struct device_attribute *attr, const char *buf, size_t count)
608 struct qeth_card *card = dev_get_drvdata(dev);
610 return qeth_dev_blkt_store(card, buf, count,
611 &card->info.blkt.inter_packet, 1000);
614 static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
615 qeth_dev_blkt_inter_store);
617 static ssize_t qeth_dev_blkt_inter_jumbo_show(struct device *dev,
618 struct device_attribute *attr, char *buf)
620 struct qeth_card *card = dev_get_drvdata(dev);
622 return sprintf(buf, "%i\n", card->info.blkt.inter_packet_jumbo);
625 static ssize_t qeth_dev_blkt_inter_jumbo_store(struct device *dev,
626 struct device_attribute *attr, const char *buf, size_t count)
628 struct qeth_card *card = dev_get_drvdata(dev);
630 return qeth_dev_blkt_store(card, buf, count,
631 &card->info.blkt.inter_packet_jumbo, 1000);
634 static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
635 qeth_dev_blkt_inter_jumbo_store);
637 static struct attribute *qeth_blkt_device_attrs[] = {
638 &dev_attr_total.attr,
639 &dev_attr_inter.attr,
640 &dev_attr_inter_jumbo.attr,
641 NULL,
644 static const struct attribute_group qeth_dev_blkt_group = {
645 .name = "blkt",
646 .attrs = qeth_blkt_device_attrs,
649 static struct attribute *qeth_dev_extended_attrs[] = {
650 &dev_attr_inbuf_size.attr,
651 &dev_attr_portno.attr,
652 &dev_attr_portname.attr,
653 &dev_attr_priority_queueing.attr,
654 &dev_attr_performance_stats.attr,
655 &dev_attr_layer2.attr,
656 &dev_attr_isolation.attr,
657 &dev_attr_hw_trap.attr,
658 &dev_attr_switch_attrs.attr,
659 NULL,
662 static const struct attribute_group qeth_dev_extended_group = {
663 .attrs = qeth_dev_extended_attrs,
666 static struct attribute *qeth_dev_attrs[] = {
667 &dev_attr_state.attr,
668 &dev_attr_chpid.attr,
669 &dev_attr_if_name.attr,
670 &dev_attr_card_type.attr,
671 &dev_attr_buffer_count.attr,
672 &dev_attr_recover.attr,
673 NULL,
676 static const struct attribute_group qeth_dev_group = {
677 .attrs = qeth_dev_attrs,
680 const struct attribute_group *qeth_osn_dev_groups[] = {
681 &qeth_dev_group,
682 NULL,
685 const struct attribute_group *qeth_dev_groups[] = {
686 &qeth_dev_group,
687 &qeth_dev_extended_group,
688 &qeth_dev_blkt_group,
689 NULL,