Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / s390 / net / qeth_l3_sys.c
blob1082380b21f852258371798d4ef93da4e5976c4d
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 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
66 static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
67 struct qeth_routing_info *route, enum qeth_prot_versions prot,
68 const char *buf, size_t count)
70 enum qeth_routing_types old_route_type = route->type;
71 int rc = 0;
73 mutex_lock(&card->conf_mutex);
74 if (sysfs_streq(buf, "no_router")) {
75 route->type = NO_ROUTER;
76 } else if (sysfs_streq(buf, "primary_connector")) {
77 route->type = PRIMARY_CONNECTOR;
78 } else if (sysfs_streq(buf, "secondary_connector")) {
79 route->type = SECONDARY_CONNECTOR;
80 } else if (sysfs_streq(buf, "primary_router")) {
81 route->type = PRIMARY_ROUTER;
82 } else if (sysfs_streq(buf, "secondary_router")) {
83 route->type = SECONDARY_ROUTER;
84 } else if (sysfs_streq(buf, "multicast_router")) {
85 route->type = MULTICAST_ROUTER;
86 } else {
87 rc = -EINVAL;
88 goto out;
90 if (qeth_card_hw_is_reachable(card) &&
91 (old_route_type != route->type)) {
92 if (prot == QETH_PROT_IPV4)
93 rc = qeth_l3_setrouting_v4(card);
94 else if (prot == QETH_PROT_IPV6)
95 rc = qeth_l3_setrouting_v6(card);
97 out:
98 if (rc)
99 route->type = old_route_type;
100 mutex_unlock(&card->conf_mutex);
101 return rc ? rc : count;
104 static ssize_t qeth_l3_dev_route4_store(struct device *dev,
105 struct device_attribute *attr, const char *buf, size_t count)
107 struct qeth_card *card = dev_get_drvdata(dev);
109 return qeth_l3_dev_route_store(card, &card->options.route4,
110 QETH_PROT_IPV4, buf, count);
113 static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
114 qeth_l3_dev_route4_store);
116 static ssize_t qeth_l3_dev_route6_show(struct device *dev,
117 struct device_attribute *attr, char *buf)
119 struct qeth_card *card = dev_get_drvdata(dev);
121 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
124 static ssize_t qeth_l3_dev_route6_store(struct device *dev,
125 struct device_attribute *attr, const char *buf, size_t count)
127 struct qeth_card *card = dev_get_drvdata(dev);
129 return qeth_l3_dev_route_store(card, &card->options.route6,
130 QETH_PROT_IPV6, buf, count);
133 static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
134 qeth_l3_dev_route6_store);
136 static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
137 struct device_attribute *attr, char *buf)
139 struct qeth_card *card = dev_get_drvdata(dev);
141 return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
144 static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
145 struct device_attribute *attr, const char *buf, size_t count)
147 struct qeth_card *card = dev_get_drvdata(dev);
148 int rc = 0;
149 unsigned long i;
151 if (!IS_IQD(card))
152 return -EPERM;
153 if (card->options.cq == QETH_CQ_ENABLED)
154 return -EPERM;
156 mutex_lock(&card->conf_mutex);
157 if (card->state != CARD_STATE_DOWN) {
158 rc = -EPERM;
159 goto out;
162 rc = kstrtoul(buf, 16, &i);
163 if (rc) {
164 rc = -EINVAL;
165 goto out;
167 switch (i) {
168 case 0:
169 card->options.sniffer = i;
170 break;
171 case 1:
172 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
173 if (card->ssqd.qdioac2 & CHSC_AC2_SNIFFER_AVAILABLE) {
174 card->options.sniffer = i;
175 qeth_resize_buffer_pool(card, QETH_IN_BUF_COUNT_MAX);
176 } else {
177 rc = -EPERM;
180 break;
181 default:
182 rc = -EINVAL;
184 out:
185 mutex_unlock(&card->conf_mutex);
186 return rc ? rc : count;
189 static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
190 qeth_l3_dev_sniffer_store);
192 static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
193 struct device_attribute *attr, char *buf)
195 struct qeth_card *card = dev_get_drvdata(dev);
196 char tmp_hsuid[9];
198 if (!IS_IQD(card))
199 return -EPERM;
201 memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
202 EBCASC(tmp_hsuid, 8);
203 return sprintf(buf, "%s\n", tmp_hsuid);
206 static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
207 struct device_attribute *attr, const char *buf, size_t count)
209 struct qeth_card *card = dev_get_drvdata(dev);
210 int rc = 0;
211 char *tmp;
213 if (!IS_IQD(card))
214 return -EPERM;
216 mutex_lock(&card->conf_mutex);
217 if (card->state != CARD_STATE_DOWN) {
218 rc = -EPERM;
219 goto out;
222 if (card->options.sniffer) {
223 rc = -EPERM;
224 goto out;
227 if (card->options.cq == QETH_CQ_NOTAVAILABLE) {
228 rc = -EPERM;
229 goto out;
232 tmp = strsep((char **)&buf, "\n");
233 if (strlen(tmp) > 8) {
234 rc = -EINVAL;
235 goto out;
238 if (card->options.hsuid[0])
239 /* delete old ip address */
240 qeth_l3_modify_hsuid(card, false);
242 if (strlen(tmp) == 0) {
243 /* delete ip address only */
244 card->options.hsuid[0] = '\0';
245 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
246 qeth_configure_cq(card, QETH_CQ_DISABLED);
247 goto out;
250 if (qeth_configure_cq(card, QETH_CQ_ENABLED)) {
251 rc = -EPERM;
252 goto out;
255 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
256 "%-8s", tmp);
257 ASCEBC(card->options.hsuid, 8);
258 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
260 rc = qeth_l3_modify_hsuid(card, true);
262 out:
263 mutex_unlock(&card->conf_mutex);
264 return rc ? rc : count;
267 static DEVICE_ATTR(hsuid, 0644, qeth_l3_dev_hsuid_show,
268 qeth_l3_dev_hsuid_store);
271 static struct attribute *qeth_l3_device_attrs[] = {
272 &dev_attr_route4.attr,
273 &dev_attr_route6.attr,
274 &dev_attr_sniffer.attr,
275 &dev_attr_hsuid.attr,
276 NULL,
279 static const struct attribute_group qeth_l3_device_attr_group = {
280 .attrs = qeth_l3_device_attrs,
283 static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
284 struct device_attribute *attr, char *buf)
286 struct qeth_card *card = dev_get_drvdata(dev);
288 return sprintf(buf, "%u\n", card->ipato.enabled ? 1 : 0);
291 static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
292 struct device_attribute *attr, const char *buf, size_t count)
294 struct qeth_card *card = dev_get_drvdata(dev);
295 bool enable;
296 int rc = 0;
298 mutex_lock(&card->conf_mutex);
299 if (card->state != CARD_STATE_DOWN) {
300 rc = -EPERM;
301 goto out;
304 mutex_lock(&card->ip_lock);
305 if (sysfs_streq(buf, "toggle")) {
306 enable = !card->ipato.enabled;
307 } else if (kstrtobool(buf, &enable)) {
308 rc = -EINVAL;
309 goto unlock_ip;
312 if (card->ipato.enabled != enable) {
313 card->ipato.enabled = enable;
314 qeth_l3_update_ipato(card);
317 unlock_ip:
318 mutex_unlock(&card->ip_lock);
319 out:
320 mutex_unlock(&card->conf_mutex);
321 return rc ? rc : count;
324 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
325 qeth_l3_dev_ipato_enable_show,
326 qeth_l3_dev_ipato_enable_store);
328 static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
329 struct device_attribute *attr, char *buf)
331 struct qeth_card *card = dev_get_drvdata(dev);
333 return sprintf(buf, "%u\n", card->ipato.invert4 ? 1 : 0);
336 static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
337 struct device_attribute *attr,
338 const char *buf, size_t count)
340 struct qeth_card *card = dev_get_drvdata(dev);
341 bool invert;
342 int rc = 0;
344 mutex_lock(&card->ip_lock);
345 if (sysfs_streq(buf, "toggle")) {
346 invert = !card->ipato.invert4;
347 } else if (kstrtobool(buf, &invert)) {
348 rc = -EINVAL;
349 goto out;
352 if (card->ipato.invert4 != invert) {
353 card->ipato.invert4 = invert;
354 qeth_l3_update_ipato(card);
357 out:
358 mutex_unlock(&card->ip_lock);
359 return rc ? rc : count;
362 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
363 qeth_l3_dev_ipato_invert4_show,
364 qeth_l3_dev_ipato_invert4_store);
366 static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
367 enum qeth_prot_versions proto)
369 struct qeth_ipato_entry *ipatoe;
370 int str_len = 0;
372 mutex_lock(&card->ip_lock);
373 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
374 char addr_str[40];
375 int entry_len;
377 if (ipatoe->proto != proto)
378 continue;
380 entry_len = qeth_l3_ipaddr_to_string(proto, ipatoe->addr,
381 addr_str);
382 if (entry_len < 0)
383 continue;
385 /* Append /%mask to the entry: */
386 entry_len += 1 + ((proto == QETH_PROT_IPV4) ? 2 : 3);
387 /* Enough room to format %entry\n into null terminated page? */
388 if (entry_len + 1 > PAGE_SIZE - str_len - 1)
389 break;
391 entry_len = scnprintf(buf, PAGE_SIZE - str_len,
392 "%s/%i\n", addr_str, ipatoe->mask_bits);
393 str_len += entry_len;
394 buf += entry_len;
396 mutex_unlock(&card->ip_lock);
398 return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
401 static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
402 struct device_attribute *attr, char *buf)
404 struct qeth_card *card = dev_get_drvdata(dev);
406 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
409 static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
410 u8 *addr, unsigned int *mask_bits)
412 char *sep;
413 int rc;
415 /* Expected input pattern: %addr/%mask */
416 sep = strnchr(buf, 40, '/');
417 if (!sep)
418 return -EINVAL;
420 /* Terminate the %addr sub-string, and parse it: */
421 *sep = '\0';
422 rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
423 if (rc)
424 return rc;
426 rc = kstrtouint(sep + 1, 10, mask_bits);
427 if (rc)
428 return rc;
430 if (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))
431 return -EINVAL;
433 return 0;
436 static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
437 struct qeth_card *card, enum qeth_prot_versions proto)
439 struct qeth_ipato_entry *ipatoe;
440 unsigned int mask_bits;
441 u8 addr[16];
442 int rc = 0;
444 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
445 if (rc)
446 return rc;
448 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
449 if (!ipatoe)
450 return -ENOMEM;
452 ipatoe->proto = proto;
453 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4) ? 4 : 16);
454 ipatoe->mask_bits = mask_bits;
456 rc = qeth_l3_add_ipato_entry(card, ipatoe);
457 if (rc)
458 kfree(ipatoe);
460 return rc ? rc : count;
463 static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
464 struct device_attribute *attr, const char *buf, size_t count)
466 struct qeth_card *card = dev_get_drvdata(dev);
468 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
471 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
472 qeth_l3_dev_ipato_add4_show,
473 qeth_l3_dev_ipato_add4_store);
475 static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
476 struct qeth_card *card, enum qeth_prot_versions proto)
478 unsigned int mask_bits;
479 u8 addr[16];
480 int rc = 0;
482 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
483 if (!rc)
484 rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
485 return rc ? rc : count;
488 static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
489 struct device_attribute *attr, const char *buf, size_t count)
491 struct qeth_card *card = dev_get_drvdata(dev);
493 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
496 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
497 qeth_l3_dev_ipato_del4_store);
499 static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
500 struct device_attribute *attr, char *buf)
502 struct qeth_card *card = dev_get_drvdata(dev);
504 return sprintf(buf, "%u\n", card->ipato.invert6 ? 1 : 0);
507 static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
508 struct device_attribute *attr, const char *buf, size_t count)
510 struct qeth_card *card = dev_get_drvdata(dev);
511 bool invert;
512 int rc = 0;
514 mutex_lock(&card->ip_lock);
515 if (sysfs_streq(buf, "toggle")) {
516 invert = !card->ipato.invert6;
517 } else if (kstrtobool(buf, &invert)) {
518 rc = -EINVAL;
519 goto out;
522 if (card->ipato.invert6 != invert) {
523 card->ipato.invert6 = invert;
524 qeth_l3_update_ipato(card);
527 out:
528 mutex_unlock(&card->ip_lock);
529 return rc ? rc : count;
532 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
533 qeth_l3_dev_ipato_invert6_show,
534 qeth_l3_dev_ipato_invert6_store);
537 static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
538 struct device_attribute *attr, char *buf)
540 struct qeth_card *card = dev_get_drvdata(dev);
542 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
545 static ssize_t qeth_l3_dev_ipato_add6_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 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
553 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
554 qeth_l3_dev_ipato_add6_show,
555 qeth_l3_dev_ipato_add6_store);
557 static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
558 struct device_attribute *attr, const char *buf, size_t count)
560 struct qeth_card *card = dev_get_drvdata(dev);
562 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
565 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
566 qeth_l3_dev_ipato_del6_store);
568 static struct attribute *qeth_ipato_device_attrs[] = {
569 &dev_attr_ipato_enable.attr,
570 &dev_attr_ipato_invert4.attr,
571 &dev_attr_ipato_add4.attr,
572 &dev_attr_ipato_del4.attr,
573 &dev_attr_ipato_invert6.attr,
574 &dev_attr_ipato_add6.attr,
575 &dev_attr_ipato_del6.attr,
576 NULL,
579 static const struct attribute_group qeth_device_ipato_group = {
580 .name = "ipa_takeover",
581 .attrs = qeth_ipato_device_attrs,
584 static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
585 enum qeth_prot_versions proto,
586 enum qeth_ip_types type)
588 struct qeth_card *card = dev_get_drvdata(dev);
589 struct qeth_ipaddr *ipaddr;
590 int str_len = 0;
591 int i;
593 mutex_lock(&card->ip_lock);
594 hash_for_each(card->ip_htable, i, ipaddr, hnode) {
595 char addr_str[40];
596 int entry_len;
598 if (ipaddr->proto != proto || ipaddr->type != type)
599 continue;
601 entry_len = qeth_l3_ipaddr_to_string(proto, (u8 *)&ipaddr->u,
602 addr_str);
603 if (entry_len < 0)
604 continue;
606 /* Enough room to format %addr\n into null terminated page? */
607 if (entry_len + 1 > PAGE_SIZE - str_len - 1)
608 break;
610 entry_len = scnprintf(buf, PAGE_SIZE - str_len, "%s\n",
611 addr_str);
612 str_len += entry_len;
613 buf += entry_len;
615 mutex_unlock(&card->ip_lock);
617 return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
620 static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
621 struct device_attribute *attr,
622 char *buf)
624 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
625 QETH_IP_TYPE_VIPA);
628 static ssize_t qeth_l3_vipa_store(struct device *dev, const char *buf, bool add,
629 size_t count, enum qeth_prot_versions proto)
631 struct qeth_card *card = dev_get_drvdata(dev);
632 u8 addr[16] = {0, };
633 int rc;
635 rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
636 if (!rc)
637 rc = qeth_l3_modify_rxip_vipa(card, add, addr,
638 QETH_IP_TYPE_VIPA, proto);
639 return rc ? rc : count;
642 static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
643 struct device_attribute *attr, const char *buf, size_t count)
645 return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
648 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
649 qeth_l3_dev_vipa_add4_show,
650 qeth_l3_dev_vipa_add4_store);
652 static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
653 struct device_attribute *attr, const char *buf, size_t count)
655 return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
658 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
659 qeth_l3_dev_vipa_del4_store);
661 static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
662 struct device_attribute *attr,
663 char *buf)
665 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
666 QETH_IP_TYPE_VIPA);
669 static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
670 struct device_attribute *attr, const char *buf, size_t count)
672 return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV6);
675 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
676 qeth_l3_dev_vipa_add6_show,
677 qeth_l3_dev_vipa_add6_store);
679 static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
680 struct device_attribute *attr, const char *buf, size_t count)
682 return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV6);
685 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
686 qeth_l3_dev_vipa_del6_store);
688 static struct attribute *qeth_vipa_device_attrs[] = {
689 &dev_attr_vipa_add4.attr,
690 &dev_attr_vipa_del4.attr,
691 &dev_attr_vipa_add6.attr,
692 &dev_attr_vipa_del6.attr,
693 NULL,
696 static const struct attribute_group qeth_device_vipa_group = {
697 .name = "vipa",
698 .attrs = qeth_vipa_device_attrs,
701 static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
702 struct device_attribute *attr,
703 char *buf)
705 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
706 QETH_IP_TYPE_RXIP);
709 static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
710 u8 *addr)
712 __be32 ipv4_addr;
713 struct in6_addr ipv6_addr;
715 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
716 return -EINVAL;
718 if (proto == QETH_PROT_IPV4) {
719 memcpy(&ipv4_addr, addr, sizeof(ipv4_addr));
720 if (ipv4_is_multicast(ipv4_addr)) {
721 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
722 return -EINVAL;
724 } else if (proto == QETH_PROT_IPV6) {
725 memcpy(&ipv6_addr, addr, sizeof(ipv6_addr));
726 if (ipv6_addr_is_multicast(&ipv6_addr)) {
727 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
728 return -EINVAL;
732 return 0;
735 static ssize_t qeth_l3_rxip_store(struct device *dev, const char *buf, bool add,
736 size_t count, enum qeth_prot_versions proto)
738 struct qeth_card *card = dev_get_drvdata(dev);
739 u8 addr[16] = {0, };
740 int rc;
742 rc = qeth_l3_parse_rxipe(buf, proto, addr);
743 if (!rc)
744 rc = qeth_l3_modify_rxip_vipa(card, add, addr,
745 QETH_IP_TYPE_RXIP, proto);
746 return rc ? rc : count;
749 static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
750 struct device_attribute *attr, const char *buf, size_t count)
752 return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV4);
755 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
756 qeth_l3_dev_rxip_add4_show,
757 qeth_l3_dev_rxip_add4_store);
759 static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
760 struct device_attribute *attr, const char *buf, size_t count)
762 return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV4);
765 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
766 qeth_l3_dev_rxip_del4_store);
768 static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
769 struct device_attribute *attr,
770 char *buf)
772 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
773 QETH_IP_TYPE_RXIP);
776 static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
777 struct device_attribute *attr, const char *buf, size_t count)
779 return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV6);
782 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
783 qeth_l3_dev_rxip_add6_show,
784 qeth_l3_dev_rxip_add6_store);
786 static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
787 struct device_attribute *attr, const char *buf, size_t count)
789 return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV6);
792 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
793 qeth_l3_dev_rxip_del6_store);
795 static struct attribute *qeth_rxip_device_attrs[] = {
796 &dev_attr_rxip_add4.attr,
797 &dev_attr_rxip_del4.attr,
798 &dev_attr_rxip_add6.attr,
799 &dev_attr_rxip_del6.attr,
800 NULL,
803 static const struct attribute_group qeth_device_rxip_group = {
804 .name = "rxip",
805 .attrs = qeth_rxip_device_attrs,
808 const struct attribute_group *qeth_l3_attr_groups[] = {
809 &qeth_l3_device_attr_group,
810 &qeth_device_ipato_group,
811 &qeth_device_vipa_group,
812 &qeth_device_rxip_group,
813 NULL,