Linux 4.18.10
[linux/fpc-iii.git] / drivers / s390 / net / qeth_l3_sys.c
blobf61192a048f447168a35e970b693c7004a490629
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 #include <linux/slab.h>
11 #include <asm/ebcdic.h>
12 #include <linux/hashtable.h>
13 #include <linux/inet.h>
14 #include "qeth_l3.h"
16 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
17 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
19 static int qeth_l3_string_to_ipaddr(const char *buf,
20 enum qeth_prot_versions proto, u8 *addr)
22 const char *end;
24 if ((proto == QETH_PROT_IPV4 && !in4_pton(buf, -1, addr, -1, &end)) ||
25 (proto == QETH_PROT_IPV6 && !in6_pton(buf, -1, addr, -1, &end)))
26 return -EINVAL;
27 return 0;
30 static ssize_t qeth_l3_dev_route_show(struct qeth_card *card,
31 struct qeth_routing_info *route, char *buf)
33 switch (route->type) {
34 case PRIMARY_ROUTER:
35 return sprintf(buf, "%s\n", "primary router");
36 case SECONDARY_ROUTER:
37 return sprintf(buf, "%s\n", "secondary router");
38 case MULTICAST_ROUTER:
39 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
40 return sprintf(buf, "%s\n", "multicast router+");
41 else
42 return sprintf(buf, "%s\n", "multicast router");
43 case PRIMARY_CONNECTOR:
44 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
45 return sprintf(buf, "%s\n", "primary connector+");
46 else
47 return sprintf(buf, "%s\n", "primary connector");
48 case SECONDARY_CONNECTOR:
49 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
50 return sprintf(buf, "%s\n", "secondary connector+");
51 else
52 return sprintf(buf, "%s\n", "secondary connector");
53 default:
54 return sprintf(buf, "%s\n", "no");
58 static ssize_t qeth_l3_dev_route4_show(struct device *dev,
59 struct device_attribute *attr, char *buf)
61 struct qeth_card *card = dev_get_drvdata(dev);
63 if (!card)
64 return -EINVAL;
66 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
69 static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
70 struct qeth_routing_info *route, enum qeth_prot_versions prot,
71 const char *buf, size_t count)
73 enum qeth_routing_types old_route_type = route->type;
74 int rc = 0;
76 mutex_lock(&card->conf_mutex);
77 if (sysfs_streq(buf, "no_router")) {
78 route->type = NO_ROUTER;
79 } else if (sysfs_streq(buf, "primary_connector")) {
80 route->type = PRIMARY_CONNECTOR;
81 } else if (sysfs_streq(buf, "secondary_connector")) {
82 route->type = SECONDARY_CONNECTOR;
83 } else if (sysfs_streq(buf, "primary_router")) {
84 route->type = PRIMARY_ROUTER;
85 } else if (sysfs_streq(buf, "secondary_router")) {
86 route->type = SECONDARY_ROUTER;
87 } else if (sysfs_streq(buf, "multicast_router")) {
88 route->type = MULTICAST_ROUTER;
89 } else {
90 rc = -EINVAL;
91 goto out;
93 if (qeth_card_hw_is_reachable(card) &&
94 (old_route_type != route->type)) {
95 if (prot == QETH_PROT_IPV4)
96 rc = qeth_l3_setrouting_v4(card);
97 else if (prot == QETH_PROT_IPV6)
98 rc = qeth_l3_setrouting_v6(card);
100 out:
101 if (rc)
102 route->type = old_route_type;
103 mutex_unlock(&card->conf_mutex);
104 return rc ? rc : count;
107 static ssize_t qeth_l3_dev_route4_store(struct device *dev,
108 struct device_attribute *attr, const char *buf, size_t count)
110 struct qeth_card *card = dev_get_drvdata(dev);
112 if (!card)
113 return -EINVAL;
115 return qeth_l3_dev_route_store(card, &card->options.route4,
116 QETH_PROT_IPV4, buf, count);
119 static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
120 qeth_l3_dev_route4_store);
122 static ssize_t qeth_l3_dev_route6_show(struct device *dev,
123 struct device_attribute *attr, char *buf)
125 struct qeth_card *card = dev_get_drvdata(dev);
127 if (!card)
128 return -EINVAL;
130 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
133 static ssize_t qeth_l3_dev_route6_store(struct device *dev,
134 struct device_attribute *attr, const char *buf, size_t count)
136 struct qeth_card *card = dev_get_drvdata(dev);
138 if (!card)
139 return -EINVAL;
141 return qeth_l3_dev_route_store(card, &card->options.route6,
142 QETH_PROT_IPV6, buf, count);
145 static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
146 qeth_l3_dev_route6_store);
148 static ssize_t qeth_l3_dev_fake_broadcast_show(struct device *dev,
149 struct device_attribute *attr, char *buf)
151 struct qeth_card *card = dev_get_drvdata(dev);
153 if (!card)
154 return -EINVAL;
156 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
159 static ssize_t qeth_l3_dev_fake_broadcast_store(struct device *dev,
160 struct device_attribute *attr, const char *buf, size_t count)
162 struct qeth_card *card = dev_get_drvdata(dev);
163 char *tmp;
164 int i, rc = 0;
166 if (!card)
167 return -EINVAL;
169 mutex_lock(&card->conf_mutex);
170 if ((card->state != CARD_STATE_DOWN) &&
171 (card->state != CARD_STATE_RECOVER)) {
172 rc = -EPERM;
173 goto out;
176 i = simple_strtoul(buf, &tmp, 16);
177 if ((i == 0) || (i == 1))
178 card->options.fake_broadcast = i;
179 else
180 rc = -EINVAL;
181 out:
182 mutex_unlock(&card->conf_mutex);
183 return rc ? rc : count;
186 static DEVICE_ATTR(fake_broadcast, 0644, qeth_l3_dev_fake_broadcast_show,
187 qeth_l3_dev_fake_broadcast_store);
189 static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
190 struct device_attribute *attr, char *buf)
192 struct qeth_card *card = dev_get_drvdata(dev);
194 if (!card)
195 return -EINVAL;
197 return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
200 static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
201 struct device_attribute *attr, const char *buf, size_t count)
203 struct qeth_card *card = dev_get_drvdata(dev);
204 int rc = 0;
205 unsigned long i;
207 if (!card)
208 return -EINVAL;
210 if (card->info.type != QETH_CARD_TYPE_IQD)
211 return -EPERM;
212 if (card->options.cq == QETH_CQ_ENABLED)
213 return -EPERM;
215 mutex_lock(&card->conf_mutex);
216 if ((card->state != CARD_STATE_DOWN) &&
217 (card->state != CARD_STATE_RECOVER)) {
218 rc = -EPERM;
219 goto out;
222 rc = kstrtoul(buf, 16, &i);
223 if (rc) {
224 rc = -EINVAL;
225 goto out;
227 switch (i) {
228 case 0:
229 card->options.sniffer = i;
230 break;
231 case 1:
232 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
233 if (card->ssqd.qdioac2 & QETH_SNIFF_AVAIL) {
234 card->options.sniffer = i;
235 if (card->qdio.init_pool.buf_count !=
236 QETH_IN_BUF_COUNT_MAX)
237 qeth_realloc_buffer_pool(card,
238 QETH_IN_BUF_COUNT_MAX);
239 } else
240 rc = -EPERM;
241 break;
242 default:
243 rc = -EINVAL;
245 out:
246 mutex_unlock(&card->conf_mutex);
247 return rc ? rc : count;
250 static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
251 qeth_l3_dev_sniffer_store);
254 static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
255 struct device_attribute *attr, char *buf)
257 struct qeth_card *card = dev_get_drvdata(dev);
258 char tmp_hsuid[9];
260 if (!card)
261 return -EINVAL;
263 if (card->info.type != QETH_CARD_TYPE_IQD)
264 return -EPERM;
266 memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
267 EBCASC(tmp_hsuid, 8);
268 return sprintf(buf, "%s\n", tmp_hsuid);
271 static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
272 struct device_attribute *attr, const char *buf, size_t count)
274 struct qeth_card *card = dev_get_drvdata(dev);
275 char *tmp;
276 int rc;
278 if (!card)
279 return -EINVAL;
281 if (card->info.type != QETH_CARD_TYPE_IQD)
282 return -EPERM;
283 if (card->state != CARD_STATE_DOWN &&
284 card->state != CARD_STATE_RECOVER)
285 return -EPERM;
286 if (card->options.sniffer)
287 return -EPERM;
288 if (card->options.cq == QETH_CQ_NOTAVAILABLE)
289 return -EPERM;
291 tmp = strsep((char **)&buf, "\n");
292 if (strlen(tmp) > 8)
293 return -EINVAL;
295 if (card->options.hsuid[0])
296 /* delete old ip address */
297 qeth_l3_modify_hsuid(card, false);
299 if (strlen(tmp) == 0) {
300 /* delete ip address only */
301 card->options.hsuid[0] = '\0';
302 if (card->dev)
303 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
304 qeth_configure_cq(card, QETH_CQ_DISABLED);
305 return count;
308 if (qeth_configure_cq(card, QETH_CQ_ENABLED))
309 return -EPERM;
311 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
312 "%-8s", tmp);
313 ASCEBC(card->options.hsuid, 8);
314 if (card->dev)
315 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
317 rc = qeth_l3_modify_hsuid(card, true);
319 return rc ? rc : count;
322 static DEVICE_ATTR(hsuid, 0644, qeth_l3_dev_hsuid_show,
323 qeth_l3_dev_hsuid_store);
326 static struct attribute *qeth_l3_device_attrs[] = {
327 &dev_attr_route4.attr,
328 &dev_attr_route6.attr,
329 &dev_attr_fake_broadcast.attr,
330 &dev_attr_sniffer.attr,
331 &dev_attr_hsuid.attr,
332 NULL,
335 static const struct attribute_group qeth_l3_device_attr_group = {
336 .attrs = qeth_l3_device_attrs,
339 static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
340 struct device_attribute *attr, char *buf)
342 struct qeth_card *card = dev_get_drvdata(dev);
344 if (!card)
345 return -EINVAL;
347 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
350 static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
351 struct device_attribute *attr, const char *buf, size_t count)
353 struct qeth_card *card = dev_get_drvdata(dev);
354 bool enable;
355 int rc = 0;
357 if (!card)
358 return -EINVAL;
360 mutex_lock(&card->conf_mutex);
361 if ((card->state != CARD_STATE_DOWN) &&
362 (card->state != CARD_STATE_RECOVER)) {
363 rc = -EPERM;
364 goto out;
367 if (sysfs_streq(buf, "toggle")) {
368 enable = !card->ipato.enabled;
369 } else if (kstrtobool(buf, &enable)) {
370 rc = -EINVAL;
371 goto out;
374 if (card->ipato.enabled != enable) {
375 card->ipato.enabled = enable;
376 spin_lock_bh(&card->ip_lock);
377 qeth_l3_update_ipato(card);
378 spin_unlock_bh(&card->ip_lock);
380 out:
381 mutex_unlock(&card->conf_mutex);
382 return rc ? rc : count;
385 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
386 qeth_l3_dev_ipato_enable_show,
387 qeth_l3_dev_ipato_enable_store);
389 static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
390 struct device_attribute *attr, char *buf)
392 struct qeth_card *card = dev_get_drvdata(dev);
394 if (!card)
395 return -EINVAL;
397 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
400 static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
401 struct device_attribute *attr,
402 const char *buf, size_t count)
404 struct qeth_card *card = dev_get_drvdata(dev);
405 bool invert;
406 int rc = 0;
408 if (!card)
409 return -EINVAL;
411 mutex_lock(&card->conf_mutex);
412 if (sysfs_streq(buf, "toggle")) {
413 invert = !card->ipato.invert4;
414 } else if (kstrtobool(buf, &invert)) {
415 rc = -EINVAL;
416 goto out;
419 if (card->ipato.invert4 != invert) {
420 card->ipato.invert4 = invert;
421 spin_lock_bh(&card->ip_lock);
422 qeth_l3_update_ipato(card);
423 spin_unlock_bh(&card->ip_lock);
425 out:
426 mutex_unlock(&card->conf_mutex);
427 return rc ? rc : count;
430 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
431 qeth_l3_dev_ipato_invert4_show,
432 qeth_l3_dev_ipato_invert4_store);
434 static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
435 enum qeth_prot_versions proto)
437 struct qeth_ipato_entry *ipatoe;
438 char addr_str[40];
439 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
440 int i = 0;
442 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
443 /* add strlen for "/<mask>\n" */
444 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
445 spin_lock_bh(&card->ip_lock);
446 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
447 if (ipatoe->proto != proto)
448 continue;
449 /* String must not be longer than PAGE_SIZE. So we check if
450 * string length gets near PAGE_SIZE. Then we can savely display
451 * the next IPv6 address (worst case, compared to IPv4) */
452 if ((PAGE_SIZE - i) <= entry_len)
453 break;
454 qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
455 i += snprintf(buf + i, PAGE_SIZE - i,
456 "%s/%i\n", addr_str, ipatoe->mask_bits);
458 spin_unlock_bh(&card->ip_lock);
459 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
461 return i;
464 static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
465 struct device_attribute *attr, char *buf)
467 struct qeth_card *card = dev_get_drvdata(dev);
469 if (!card)
470 return -EINVAL;
472 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
475 static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
476 u8 *addr, int *mask_bits)
478 const char *start, *end;
479 char *tmp;
480 char buffer[40] = {0, };
482 start = buf;
483 /* get address string */
484 end = strchr(start, '/');
485 if (!end || (end - start >= 40)) {
486 return -EINVAL;
488 strncpy(buffer, start, end - start);
489 if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
490 return -EINVAL;
492 start = end + 1;
493 *mask_bits = simple_strtoul(start, &tmp, 10);
494 if (!strlen(start) ||
495 (tmp == start) ||
496 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
497 return -EINVAL;
499 return 0;
502 static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
503 struct qeth_card *card, enum qeth_prot_versions proto)
505 struct qeth_ipato_entry *ipatoe;
506 u8 addr[16];
507 int mask_bits;
508 int rc = 0;
510 mutex_lock(&card->conf_mutex);
511 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
512 if (rc)
513 goto out;
515 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
516 if (!ipatoe) {
517 rc = -ENOMEM;
518 goto out;
520 ipatoe->proto = proto;
521 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
522 ipatoe->mask_bits = mask_bits;
524 rc = qeth_l3_add_ipato_entry(card, ipatoe);
525 if (rc)
526 kfree(ipatoe);
527 out:
528 mutex_unlock(&card->conf_mutex);
529 return rc ? rc : count;
532 static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
533 struct device_attribute *attr, const char *buf, size_t count)
535 struct qeth_card *card = dev_get_drvdata(dev);
537 if (!card)
538 return -EINVAL;
540 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
543 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
544 qeth_l3_dev_ipato_add4_show,
545 qeth_l3_dev_ipato_add4_store);
547 static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
548 struct qeth_card *card, enum qeth_prot_versions proto)
550 u8 addr[16];
551 int mask_bits;
552 int rc = 0;
554 mutex_lock(&card->conf_mutex);
555 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
556 if (!rc)
557 rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
558 mutex_unlock(&card->conf_mutex);
559 return rc ? rc : count;
562 static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
563 struct device_attribute *attr, const char *buf, size_t count)
565 struct qeth_card *card = dev_get_drvdata(dev);
567 if (!card)
568 return -EINVAL;
570 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
573 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
574 qeth_l3_dev_ipato_del4_store);
576 static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
577 struct device_attribute *attr, char *buf)
579 struct qeth_card *card = dev_get_drvdata(dev);
581 if (!card)
582 return -EINVAL;
584 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
587 static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
588 struct device_attribute *attr, const char *buf, size_t count)
590 struct qeth_card *card = dev_get_drvdata(dev);
591 bool invert;
592 int rc = 0;
594 if (!card)
595 return -EINVAL;
597 mutex_lock(&card->conf_mutex);
598 if (sysfs_streq(buf, "toggle")) {
599 invert = !card->ipato.invert6;
600 } else if (kstrtobool(buf, &invert)) {
601 rc = -EINVAL;
602 goto out;
605 if (card->ipato.invert6 != invert) {
606 card->ipato.invert6 = invert;
607 spin_lock_bh(&card->ip_lock);
608 qeth_l3_update_ipato(card);
609 spin_unlock_bh(&card->ip_lock);
611 out:
612 mutex_unlock(&card->conf_mutex);
613 return rc ? rc : count;
616 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
617 qeth_l3_dev_ipato_invert6_show,
618 qeth_l3_dev_ipato_invert6_store);
621 static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
622 struct device_attribute *attr, char *buf)
624 struct qeth_card *card = dev_get_drvdata(dev);
626 if (!card)
627 return -EINVAL;
629 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
632 static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
633 struct device_attribute *attr, const char *buf, size_t count)
635 struct qeth_card *card = dev_get_drvdata(dev);
637 if (!card)
638 return -EINVAL;
640 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
643 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
644 qeth_l3_dev_ipato_add6_show,
645 qeth_l3_dev_ipato_add6_store);
647 static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
648 struct device_attribute *attr, const char *buf, size_t count)
650 struct qeth_card *card = dev_get_drvdata(dev);
652 if (!card)
653 return -EINVAL;
655 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
658 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
659 qeth_l3_dev_ipato_del6_store);
661 static struct attribute *qeth_ipato_device_attrs[] = {
662 &dev_attr_ipato_enable.attr,
663 &dev_attr_ipato_invert4.attr,
664 &dev_attr_ipato_add4.attr,
665 &dev_attr_ipato_del4.attr,
666 &dev_attr_ipato_invert6.attr,
667 &dev_attr_ipato_add6.attr,
668 &dev_attr_ipato_del6.attr,
669 NULL,
672 static const struct attribute_group qeth_device_ipato_group = {
673 .name = "ipa_takeover",
674 .attrs = qeth_ipato_device_attrs,
677 static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
678 enum qeth_prot_versions proto,
679 enum qeth_ip_types type)
681 struct qeth_card *card = dev_get_drvdata(dev);
682 struct qeth_ipaddr *ipaddr;
683 char addr_str[40];
684 int str_len = 0;
685 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
686 int i;
688 if (!card)
689 return -EINVAL;
691 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
692 entry_len += 2; /* \n + terminator */
693 spin_lock_bh(&card->ip_lock);
694 hash_for_each(card->ip_htable, i, ipaddr, hnode) {
695 if (ipaddr->proto != proto || ipaddr->type != type)
696 continue;
697 /* String must not be longer than PAGE_SIZE. So we check if
698 * string length gets near PAGE_SIZE. Then we can savely display
699 * the next IPv6 address (worst case, compared to IPv4) */
700 if ((PAGE_SIZE - str_len) <= entry_len)
701 break;
702 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
703 addr_str);
704 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "%s\n",
705 addr_str);
707 spin_unlock_bh(&card->ip_lock);
708 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "\n");
710 return str_len;
713 static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
714 struct device_attribute *attr,
715 char *buf)
717 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
718 QETH_IP_TYPE_VIPA);
721 static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
722 u8 *addr)
724 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
725 return -EINVAL;
727 return 0;
730 static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
731 struct qeth_card *card, enum qeth_prot_versions proto)
733 u8 addr[16] = {0, };
734 int rc;
736 mutex_lock(&card->conf_mutex);
737 rc = qeth_l3_parse_vipae(buf, proto, addr);
738 if (!rc)
739 rc = qeth_l3_modify_rxip_vipa(card, true, addr,
740 QETH_IP_TYPE_VIPA, proto);
741 mutex_unlock(&card->conf_mutex);
742 return rc ? rc : count;
745 static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
746 struct device_attribute *attr, const char *buf, size_t count)
748 struct qeth_card *card = dev_get_drvdata(dev);
750 if (!card)
751 return -EINVAL;
753 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
756 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
757 qeth_l3_dev_vipa_add4_show,
758 qeth_l3_dev_vipa_add4_store);
760 static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
761 struct qeth_card *card, enum qeth_prot_versions proto)
763 u8 addr[16];
764 int rc;
766 mutex_lock(&card->conf_mutex);
767 rc = qeth_l3_parse_vipae(buf, proto, addr);
768 if (!rc)
769 rc = qeth_l3_modify_rxip_vipa(card, false, addr,
770 QETH_IP_TYPE_VIPA, proto);
771 mutex_unlock(&card->conf_mutex);
772 return rc ? rc : count;
775 static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
776 struct device_attribute *attr, const char *buf, size_t count)
778 struct qeth_card *card = dev_get_drvdata(dev);
780 if (!card)
781 return -EINVAL;
783 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
786 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
787 qeth_l3_dev_vipa_del4_store);
789 static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
790 struct device_attribute *attr,
791 char *buf)
793 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
794 QETH_IP_TYPE_VIPA);
797 static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
798 struct device_attribute *attr, const char *buf, size_t count)
800 struct qeth_card *card = dev_get_drvdata(dev);
802 if (!card)
803 return -EINVAL;
805 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
808 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
809 qeth_l3_dev_vipa_add6_show,
810 qeth_l3_dev_vipa_add6_store);
812 static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
813 struct device_attribute *attr, const char *buf, size_t count)
815 struct qeth_card *card = dev_get_drvdata(dev);
817 if (!card)
818 return -EINVAL;
820 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
823 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
824 qeth_l3_dev_vipa_del6_store);
826 static struct attribute *qeth_vipa_device_attrs[] = {
827 &dev_attr_vipa_add4.attr,
828 &dev_attr_vipa_del4.attr,
829 &dev_attr_vipa_add6.attr,
830 &dev_attr_vipa_del6.attr,
831 NULL,
834 static const struct attribute_group qeth_device_vipa_group = {
835 .name = "vipa",
836 .attrs = qeth_vipa_device_attrs,
839 static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
840 struct device_attribute *attr,
841 char *buf)
843 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
844 QETH_IP_TYPE_RXIP);
847 static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
848 u8 *addr)
850 __be32 ipv4_addr;
851 struct in6_addr ipv6_addr;
853 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
854 return -EINVAL;
856 if (proto == QETH_PROT_IPV4) {
857 memcpy(&ipv4_addr, addr, sizeof(ipv4_addr));
858 if (ipv4_is_multicast(ipv4_addr)) {
859 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
860 return -EINVAL;
862 } else if (proto == QETH_PROT_IPV6) {
863 memcpy(&ipv6_addr, addr, sizeof(ipv6_addr));
864 if (ipv6_addr_is_multicast(&ipv6_addr)) {
865 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
866 return -EINVAL;
870 return 0;
873 static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
874 struct qeth_card *card, enum qeth_prot_versions proto)
876 u8 addr[16] = {0, };
877 int rc;
879 mutex_lock(&card->conf_mutex);
880 rc = qeth_l3_parse_rxipe(buf, proto, addr);
881 if (!rc)
882 rc = qeth_l3_modify_rxip_vipa(card, true, addr,
883 QETH_IP_TYPE_RXIP, proto);
884 mutex_unlock(&card->conf_mutex);
885 return rc ? rc : count;
888 static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
889 struct device_attribute *attr, const char *buf, size_t count)
891 struct qeth_card *card = dev_get_drvdata(dev);
893 if (!card)
894 return -EINVAL;
896 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
899 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
900 qeth_l3_dev_rxip_add4_show,
901 qeth_l3_dev_rxip_add4_store);
903 static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
904 struct qeth_card *card, enum qeth_prot_versions proto)
906 u8 addr[16];
907 int rc;
909 mutex_lock(&card->conf_mutex);
910 rc = qeth_l3_parse_rxipe(buf, proto, addr);
911 if (!rc)
912 rc = qeth_l3_modify_rxip_vipa(card, false, addr,
913 QETH_IP_TYPE_RXIP, proto);
914 mutex_unlock(&card->conf_mutex);
915 return rc ? rc : count;
918 static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
919 struct device_attribute *attr, const char *buf, size_t count)
921 struct qeth_card *card = dev_get_drvdata(dev);
923 if (!card)
924 return -EINVAL;
926 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
929 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
930 qeth_l3_dev_rxip_del4_store);
932 static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
933 struct device_attribute *attr,
934 char *buf)
936 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
937 QETH_IP_TYPE_RXIP);
940 static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
941 struct device_attribute *attr, const char *buf, size_t count)
943 struct qeth_card *card = dev_get_drvdata(dev);
945 if (!card)
946 return -EINVAL;
948 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
951 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
952 qeth_l3_dev_rxip_add6_show,
953 qeth_l3_dev_rxip_add6_store);
955 static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
956 struct device_attribute *attr, const char *buf, size_t count)
958 struct qeth_card *card = dev_get_drvdata(dev);
960 if (!card)
961 return -EINVAL;
963 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
966 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
967 qeth_l3_dev_rxip_del6_store);
969 static struct attribute *qeth_rxip_device_attrs[] = {
970 &dev_attr_rxip_add4.attr,
971 &dev_attr_rxip_del4.attr,
972 &dev_attr_rxip_add6.attr,
973 &dev_attr_rxip_del6.attr,
974 NULL,
977 static const struct attribute_group qeth_device_rxip_group = {
978 .name = "rxip",
979 .attrs = qeth_rxip_device_attrs,
982 static const struct attribute_group *qeth_l3_only_attr_groups[] = {
983 &qeth_l3_device_attr_group,
984 &qeth_device_ipato_group,
985 &qeth_device_vipa_group,
986 &qeth_device_rxip_group,
987 NULL,
990 int qeth_l3_create_device_attributes(struct device *dev)
992 return sysfs_create_groups(&dev->kobj, qeth_l3_only_attr_groups);
995 void qeth_l3_remove_device_attributes(struct device *dev)
997 sysfs_remove_groups(&dev->kobj, qeth_l3_only_attr_groups);
1000 const struct attribute_group *qeth_l3_attr_groups[] = {
1001 &qeth_device_attr_group,
1002 &qeth_device_blkt_group,
1003 /* l3 specific, see qeth_l3_only_attr_groups: */
1004 &qeth_l3_device_attr_group,
1005 &qeth_device_ipato_group,
1006 &qeth_device_vipa_group,
1007 &qeth_device_rxip_group,
1008 NULL,