1 // SPDX-License-Identifier: GPL-2.0
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>
10 #include <linux/slab.h>
11 #include <asm/ebcdic.h>
12 #include <linux/hashtable.h>
13 #include <linux/inet.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
)
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
)))
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
) {
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+");
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+");
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+");
52 return sprintf(buf
, "%s\n", "secondary connector");
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
);
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
;
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
;
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
);
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
);
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
);
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
);
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
);
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
);
169 mutex_lock(&card
->conf_mutex
);
170 if ((card
->state
!= CARD_STATE_DOWN
) &&
171 (card
->state
!= CARD_STATE_RECOVER
)) {
176 i
= simple_strtoul(buf
, &tmp
, 16);
177 if ((i
== 0) || (i
== 1))
178 card
->options
.fake_broadcast
= i
;
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
);
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
);
210 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
212 if (card
->options
.cq
== QETH_CQ_ENABLED
)
215 mutex_lock(&card
->conf_mutex
);
216 if ((card
->state
!= CARD_STATE_DOWN
) &&
217 (card
->state
!= CARD_STATE_RECOVER
)) {
222 rc
= kstrtoul(buf
, 16, &i
);
229 card
->options
.sniffer
= i
;
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
);
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
);
263 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
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 struct qeth_ipaddr
*addr
;
282 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
284 if (card
->state
!= CARD_STATE_DOWN
&&
285 card
->state
!= CARD_STATE_RECOVER
)
287 if (card
->options
.sniffer
)
289 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
)
292 tmp
= strsep((char **)&buf
, "\n");
296 if (card
->options
.hsuid
[0]) {
297 /* delete old ip address */
298 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
302 addr
->u
.a6
.addr
.s6_addr32
[0] = cpu_to_be32(0xfe800000);
303 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
304 for (i
= 8; i
< 16; i
++)
305 addr
->u
.a6
.addr
.s6_addr
[i
] =
306 card
->options
.hsuid
[i
- 8];
307 addr
->u
.a6
.pfxlen
= 0;
308 addr
->type
= QETH_IP_TYPE_NORMAL
;
310 spin_lock_bh(&card
->ip_lock
);
311 qeth_l3_delete_ip(card
, addr
);
312 spin_unlock_bh(&card
->ip_lock
);
316 if (strlen(tmp
) == 0) {
317 /* delete ip address only */
318 card
->options
.hsuid
[0] = '\0';
320 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
321 qeth_configure_cq(card
, QETH_CQ_DISABLED
);
325 if (qeth_configure_cq(card
, QETH_CQ_ENABLED
))
328 snprintf(card
->options
.hsuid
, sizeof(card
->options
.hsuid
),
330 ASCEBC(card
->options
.hsuid
, 8);
332 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
334 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
336 addr
->u
.a6
.addr
.s6_addr32
[0] = cpu_to_be32(0xfe800000);
337 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
338 for (i
= 8; i
< 16; i
++)
339 addr
->u
.a6
.addr
.s6_addr
[i
] = card
->options
.hsuid
[i
- 8];
340 addr
->u
.a6
.pfxlen
= 0;
341 addr
->type
= QETH_IP_TYPE_NORMAL
;
345 spin_lock_bh(&card
->ip_lock
);
346 rc
= qeth_l3_add_ip(card
, addr
);
347 spin_unlock_bh(&card
->ip_lock
);
350 return rc
? rc
: count
;
353 static DEVICE_ATTR(hsuid
, 0644, qeth_l3_dev_hsuid_show
,
354 qeth_l3_dev_hsuid_store
);
357 static struct attribute
*qeth_l3_device_attrs
[] = {
358 &dev_attr_route4
.attr
,
359 &dev_attr_route6
.attr
,
360 &dev_attr_fake_broadcast
.attr
,
361 &dev_attr_sniffer
.attr
,
362 &dev_attr_hsuid
.attr
,
366 static const struct attribute_group qeth_l3_device_attr_group
= {
367 .attrs
= qeth_l3_device_attrs
,
370 static ssize_t
qeth_l3_dev_ipato_enable_show(struct device
*dev
,
371 struct device_attribute
*attr
, char *buf
)
373 struct qeth_card
*card
= dev_get_drvdata(dev
);
378 return sprintf(buf
, "%i\n", card
->ipato
.enabled
? 1:0);
381 static ssize_t
qeth_l3_dev_ipato_enable_store(struct device
*dev
,
382 struct device_attribute
*attr
, const char *buf
, size_t count
)
384 struct qeth_card
*card
= dev_get_drvdata(dev
);
391 mutex_lock(&card
->conf_mutex
);
392 if ((card
->state
!= CARD_STATE_DOWN
) &&
393 (card
->state
!= CARD_STATE_RECOVER
)) {
398 if (sysfs_streq(buf
, "toggle")) {
399 enable
= !card
->ipato
.enabled
;
400 } else if (kstrtobool(buf
, &enable
)) {
405 if (card
->ipato
.enabled
!= enable
) {
406 card
->ipato
.enabled
= enable
;
407 spin_lock_bh(&card
->ip_lock
);
408 qeth_l3_update_ipato(card
);
409 spin_unlock_bh(&card
->ip_lock
);
412 mutex_unlock(&card
->conf_mutex
);
413 return rc
? rc
: count
;
416 static QETH_DEVICE_ATTR(ipato_enable
, enable
, 0644,
417 qeth_l3_dev_ipato_enable_show
,
418 qeth_l3_dev_ipato_enable_store
);
420 static ssize_t
qeth_l3_dev_ipato_invert4_show(struct device
*dev
,
421 struct device_attribute
*attr
, char *buf
)
423 struct qeth_card
*card
= dev_get_drvdata(dev
);
428 return sprintf(buf
, "%i\n", card
->ipato
.invert4
? 1:0);
431 static ssize_t
qeth_l3_dev_ipato_invert4_store(struct device
*dev
,
432 struct device_attribute
*attr
,
433 const char *buf
, size_t count
)
435 struct qeth_card
*card
= dev_get_drvdata(dev
);
442 mutex_lock(&card
->conf_mutex
);
443 if (sysfs_streq(buf
, "toggle")) {
444 invert
= !card
->ipato
.invert4
;
445 } else if (kstrtobool(buf
, &invert
)) {
450 if (card
->ipato
.invert4
!= invert
) {
451 card
->ipato
.invert4
= invert
;
452 spin_lock_bh(&card
->ip_lock
);
453 qeth_l3_update_ipato(card
);
454 spin_unlock_bh(&card
->ip_lock
);
457 mutex_unlock(&card
->conf_mutex
);
458 return rc
? rc
: count
;
461 static QETH_DEVICE_ATTR(ipato_invert4
, invert4
, 0644,
462 qeth_l3_dev_ipato_invert4_show
,
463 qeth_l3_dev_ipato_invert4_store
);
465 static ssize_t
qeth_l3_dev_ipato_add_show(char *buf
, struct qeth_card
*card
,
466 enum qeth_prot_versions proto
)
468 struct qeth_ipato_entry
*ipatoe
;
470 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
473 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
474 /* add strlen for "/<mask>\n" */
475 entry_len
+= (proto
== QETH_PROT_IPV4
)? 5 : 6;
476 spin_lock_bh(&card
->ip_lock
);
477 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
478 if (ipatoe
->proto
!= proto
)
480 /* String must not be longer than PAGE_SIZE. So we check if
481 * string length gets near PAGE_SIZE. Then we can savely display
482 * the next IPv6 address (worst case, compared to IPv4) */
483 if ((PAGE_SIZE
- i
) <= entry_len
)
485 qeth_l3_ipaddr_to_string(proto
, ipatoe
->addr
, addr_str
);
486 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
,
487 "%s/%i\n", addr_str
, ipatoe
->mask_bits
);
489 spin_unlock_bh(&card
->ip_lock
);
490 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
495 static ssize_t
qeth_l3_dev_ipato_add4_show(struct device
*dev
,
496 struct device_attribute
*attr
, char *buf
)
498 struct qeth_card
*card
= dev_get_drvdata(dev
);
503 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV4
);
506 static int qeth_l3_parse_ipatoe(const char *buf
, enum qeth_prot_versions proto
,
507 u8
*addr
, int *mask_bits
)
509 const char *start
, *end
;
511 char buffer
[40] = {0, };
514 /* get address string */
515 end
= strchr(start
, '/');
516 if (!end
|| (end
- start
>= 40)) {
519 strncpy(buffer
, start
, end
- start
);
520 if (qeth_l3_string_to_ipaddr(buffer
, proto
, addr
)) {
524 *mask_bits
= simple_strtoul(start
, &tmp
, 10);
525 if (!strlen(start
) ||
527 (*mask_bits
> ((proto
== QETH_PROT_IPV4
) ? 32 : 128))) {
533 static ssize_t
qeth_l3_dev_ipato_add_store(const char *buf
, size_t count
,
534 struct qeth_card
*card
, enum qeth_prot_versions proto
)
536 struct qeth_ipato_entry
*ipatoe
;
541 mutex_lock(&card
->conf_mutex
);
542 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
546 ipatoe
= kzalloc(sizeof(struct qeth_ipato_entry
), GFP_KERNEL
);
551 ipatoe
->proto
= proto
;
552 memcpy(ipatoe
->addr
, addr
, (proto
== QETH_PROT_IPV4
)? 4:16);
553 ipatoe
->mask_bits
= mask_bits
;
555 rc
= qeth_l3_add_ipato_entry(card
, ipatoe
);
559 mutex_unlock(&card
->conf_mutex
);
560 return rc
? rc
: count
;
563 static ssize_t
qeth_l3_dev_ipato_add4_store(struct device
*dev
,
564 struct device_attribute
*attr
, const char *buf
, size_t count
)
566 struct qeth_card
*card
= dev_get_drvdata(dev
);
571 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
574 static QETH_DEVICE_ATTR(ipato_add4
, add4
, 0644,
575 qeth_l3_dev_ipato_add4_show
,
576 qeth_l3_dev_ipato_add4_store
);
578 static ssize_t
qeth_l3_dev_ipato_del_store(const char *buf
, size_t count
,
579 struct qeth_card
*card
, enum qeth_prot_versions proto
)
585 mutex_lock(&card
->conf_mutex
);
586 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
588 rc
= qeth_l3_del_ipato_entry(card
, proto
, addr
, mask_bits
);
589 mutex_unlock(&card
->conf_mutex
);
590 return rc
? rc
: count
;
593 static ssize_t
qeth_l3_dev_ipato_del4_store(struct device
*dev
,
594 struct device_attribute
*attr
, const char *buf
, size_t count
)
596 struct qeth_card
*card
= dev_get_drvdata(dev
);
601 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
604 static QETH_DEVICE_ATTR(ipato_del4
, del4
, 0200, NULL
,
605 qeth_l3_dev_ipato_del4_store
);
607 static ssize_t
qeth_l3_dev_ipato_invert6_show(struct device
*dev
,
608 struct device_attribute
*attr
, char *buf
)
610 struct qeth_card
*card
= dev_get_drvdata(dev
);
615 return sprintf(buf
, "%i\n", card
->ipato
.invert6
? 1:0);
618 static ssize_t
qeth_l3_dev_ipato_invert6_store(struct device
*dev
,
619 struct device_attribute
*attr
, const char *buf
, size_t count
)
621 struct qeth_card
*card
= dev_get_drvdata(dev
);
628 mutex_lock(&card
->conf_mutex
);
629 if (sysfs_streq(buf
, "toggle")) {
630 invert
= !card
->ipato
.invert6
;
631 } else if (kstrtobool(buf
, &invert
)) {
636 if (card
->ipato
.invert6
!= invert
) {
637 card
->ipato
.invert6
= invert
;
638 spin_lock_bh(&card
->ip_lock
);
639 qeth_l3_update_ipato(card
);
640 spin_unlock_bh(&card
->ip_lock
);
643 mutex_unlock(&card
->conf_mutex
);
644 return rc
? rc
: count
;
647 static QETH_DEVICE_ATTR(ipato_invert6
, invert6
, 0644,
648 qeth_l3_dev_ipato_invert6_show
,
649 qeth_l3_dev_ipato_invert6_store
);
652 static ssize_t
qeth_l3_dev_ipato_add6_show(struct device
*dev
,
653 struct device_attribute
*attr
, char *buf
)
655 struct qeth_card
*card
= dev_get_drvdata(dev
);
660 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV6
);
663 static ssize_t
qeth_l3_dev_ipato_add6_store(struct device
*dev
,
664 struct device_attribute
*attr
, const char *buf
, size_t count
)
666 struct qeth_card
*card
= dev_get_drvdata(dev
);
671 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
674 static QETH_DEVICE_ATTR(ipato_add6
, add6
, 0644,
675 qeth_l3_dev_ipato_add6_show
,
676 qeth_l3_dev_ipato_add6_store
);
678 static ssize_t
qeth_l3_dev_ipato_del6_store(struct device
*dev
,
679 struct device_attribute
*attr
, const char *buf
, size_t count
)
681 struct qeth_card
*card
= dev_get_drvdata(dev
);
686 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
689 static QETH_DEVICE_ATTR(ipato_del6
, del6
, 0200, NULL
,
690 qeth_l3_dev_ipato_del6_store
);
692 static struct attribute
*qeth_ipato_device_attrs
[] = {
693 &dev_attr_ipato_enable
.attr
,
694 &dev_attr_ipato_invert4
.attr
,
695 &dev_attr_ipato_add4
.attr
,
696 &dev_attr_ipato_del4
.attr
,
697 &dev_attr_ipato_invert6
.attr
,
698 &dev_attr_ipato_add6
.attr
,
699 &dev_attr_ipato_del6
.attr
,
703 static const struct attribute_group qeth_device_ipato_group
= {
704 .name
= "ipa_takeover",
705 .attrs
= qeth_ipato_device_attrs
,
708 static ssize_t
qeth_l3_dev_ip_add_show(struct device
*dev
, char *buf
,
709 enum qeth_prot_versions proto
,
710 enum qeth_ip_types type
)
712 struct qeth_card
*card
= dev_get_drvdata(dev
);
713 struct qeth_ipaddr
*ipaddr
;
716 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
722 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
723 entry_len
+= 2; /* \n + terminator */
724 spin_lock_bh(&card
->ip_lock
);
725 hash_for_each(card
->ip_htable
, i
, ipaddr
, hnode
) {
726 if (ipaddr
->proto
!= proto
|| ipaddr
->type
!= type
)
728 /* String must not be longer than PAGE_SIZE. So we check if
729 * string length gets near PAGE_SIZE. Then we can savely display
730 * the next IPv6 address (worst case, compared to IPv4) */
731 if ((PAGE_SIZE
- str_len
) <= entry_len
)
733 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
735 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "%s\n",
738 spin_unlock_bh(&card
->ip_lock
);
739 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "\n");
744 static ssize_t
qeth_l3_dev_vipa_add4_show(struct device
*dev
,
745 struct device_attribute
*attr
,
748 return qeth_l3_dev_ip_add_show(dev
, buf
, QETH_PROT_IPV4
,
752 static int qeth_l3_parse_vipae(const char *buf
, enum qeth_prot_versions proto
,
755 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
761 static ssize_t
qeth_l3_dev_vipa_add_store(const char *buf
, size_t count
,
762 struct qeth_card
*card
, enum qeth_prot_versions proto
)
767 mutex_lock(&card
->conf_mutex
);
768 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
770 rc
= qeth_l3_add_vipa(card
, proto
, addr
);
771 mutex_unlock(&card
->conf_mutex
);
772 return rc
? rc
: count
;
775 static ssize_t
qeth_l3_dev_vipa_add4_store(struct device
*dev
,
776 struct device_attribute
*attr
, const char *buf
, size_t count
)
778 struct qeth_card
*card
= dev_get_drvdata(dev
);
783 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
786 static QETH_DEVICE_ATTR(vipa_add4
, add4
, 0644,
787 qeth_l3_dev_vipa_add4_show
,
788 qeth_l3_dev_vipa_add4_store
);
790 static ssize_t
qeth_l3_dev_vipa_del_store(const char *buf
, size_t count
,
791 struct qeth_card
*card
, enum qeth_prot_versions proto
)
796 mutex_lock(&card
->conf_mutex
);
797 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
799 rc
= qeth_l3_del_vipa(card
, proto
, addr
);
800 mutex_unlock(&card
->conf_mutex
);
801 return rc
? rc
: count
;
804 static ssize_t
qeth_l3_dev_vipa_del4_store(struct device
*dev
,
805 struct device_attribute
*attr
, const char *buf
, size_t count
)
807 struct qeth_card
*card
= dev_get_drvdata(dev
);
812 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
815 static QETH_DEVICE_ATTR(vipa_del4
, del4
, 0200, NULL
,
816 qeth_l3_dev_vipa_del4_store
);
818 static ssize_t
qeth_l3_dev_vipa_add6_show(struct device
*dev
,
819 struct device_attribute
*attr
,
822 return qeth_l3_dev_ip_add_show(dev
, buf
, QETH_PROT_IPV6
,
826 static ssize_t
qeth_l3_dev_vipa_add6_store(struct device
*dev
,
827 struct device_attribute
*attr
, const char *buf
, size_t count
)
829 struct qeth_card
*card
= dev_get_drvdata(dev
);
834 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
837 static QETH_DEVICE_ATTR(vipa_add6
, add6
, 0644,
838 qeth_l3_dev_vipa_add6_show
,
839 qeth_l3_dev_vipa_add6_store
);
841 static ssize_t
qeth_l3_dev_vipa_del6_store(struct device
*dev
,
842 struct device_attribute
*attr
, const char *buf
, size_t count
)
844 struct qeth_card
*card
= dev_get_drvdata(dev
);
849 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
852 static QETH_DEVICE_ATTR(vipa_del6
, del6
, 0200, NULL
,
853 qeth_l3_dev_vipa_del6_store
);
855 static struct attribute
*qeth_vipa_device_attrs
[] = {
856 &dev_attr_vipa_add4
.attr
,
857 &dev_attr_vipa_del4
.attr
,
858 &dev_attr_vipa_add6
.attr
,
859 &dev_attr_vipa_del6
.attr
,
863 static const struct attribute_group qeth_device_vipa_group
= {
865 .attrs
= qeth_vipa_device_attrs
,
868 static ssize_t
qeth_l3_dev_rxip_add4_show(struct device
*dev
,
869 struct device_attribute
*attr
,
872 return qeth_l3_dev_ip_add_show(dev
, buf
, QETH_PROT_IPV4
,
876 static int qeth_l3_parse_rxipe(const char *buf
, enum qeth_prot_versions proto
,
880 struct in6_addr ipv6_addr
;
882 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
885 if (proto
== QETH_PROT_IPV4
) {
886 memcpy(&ipv4_addr
, addr
, sizeof(ipv4_addr
));
887 if (ipv4_is_multicast(ipv4_addr
)) {
888 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
891 } else if (proto
== QETH_PROT_IPV6
) {
892 memcpy(&ipv6_addr
, addr
, sizeof(ipv6_addr
));
893 if (ipv6_addr_is_multicast(&ipv6_addr
)) {
894 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
902 static ssize_t
qeth_l3_dev_rxip_add_store(const char *buf
, size_t count
,
903 struct qeth_card
*card
, enum qeth_prot_versions proto
)
908 mutex_lock(&card
->conf_mutex
);
909 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
911 rc
= qeth_l3_add_rxip(card
, proto
, addr
);
912 mutex_unlock(&card
->conf_mutex
);
913 return rc
? rc
: count
;
916 static ssize_t
qeth_l3_dev_rxip_add4_store(struct device
*dev
,
917 struct device_attribute
*attr
, const char *buf
, size_t count
)
919 struct qeth_card
*card
= dev_get_drvdata(dev
);
924 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
927 static QETH_DEVICE_ATTR(rxip_add4
, add4
, 0644,
928 qeth_l3_dev_rxip_add4_show
,
929 qeth_l3_dev_rxip_add4_store
);
931 static ssize_t
qeth_l3_dev_rxip_del_store(const char *buf
, size_t count
,
932 struct qeth_card
*card
, enum qeth_prot_versions proto
)
937 mutex_lock(&card
->conf_mutex
);
938 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
940 rc
= qeth_l3_del_rxip(card
, proto
, addr
);
941 mutex_unlock(&card
->conf_mutex
);
942 return rc
? rc
: count
;
945 static ssize_t
qeth_l3_dev_rxip_del4_store(struct device
*dev
,
946 struct device_attribute
*attr
, const char *buf
, size_t count
)
948 struct qeth_card
*card
= dev_get_drvdata(dev
);
953 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
956 static QETH_DEVICE_ATTR(rxip_del4
, del4
, 0200, NULL
,
957 qeth_l3_dev_rxip_del4_store
);
959 static ssize_t
qeth_l3_dev_rxip_add6_show(struct device
*dev
,
960 struct device_attribute
*attr
,
963 return qeth_l3_dev_ip_add_show(dev
, buf
, QETH_PROT_IPV6
,
967 static ssize_t
qeth_l3_dev_rxip_add6_store(struct device
*dev
,
968 struct device_attribute
*attr
, const char *buf
, size_t count
)
970 struct qeth_card
*card
= dev_get_drvdata(dev
);
975 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
978 static QETH_DEVICE_ATTR(rxip_add6
, add6
, 0644,
979 qeth_l3_dev_rxip_add6_show
,
980 qeth_l3_dev_rxip_add6_store
);
982 static ssize_t
qeth_l3_dev_rxip_del6_store(struct device
*dev
,
983 struct device_attribute
*attr
, const char *buf
, size_t count
)
985 struct qeth_card
*card
= dev_get_drvdata(dev
);
990 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
993 static QETH_DEVICE_ATTR(rxip_del6
, del6
, 0200, NULL
,
994 qeth_l3_dev_rxip_del6_store
);
996 static struct attribute
*qeth_rxip_device_attrs
[] = {
997 &dev_attr_rxip_add4
.attr
,
998 &dev_attr_rxip_del4
.attr
,
999 &dev_attr_rxip_add6
.attr
,
1000 &dev_attr_rxip_del6
.attr
,
1004 static const struct attribute_group qeth_device_rxip_group
= {
1006 .attrs
= qeth_rxip_device_attrs
,
1009 static const struct attribute_group
*qeth_l3_only_attr_groups
[] = {
1010 &qeth_l3_device_attr_group
,
1011 &qeth_device_ipato_group
,
1012 &qeth_device_vipa_group
,
1013 &qeth_device_rxip_group
,
1017 int qeth_l3_create_device_attributes(struct device
*dev
)
1019 return sysfs_create_groups(&dev
->kobj
, qeth_l3_only_attr_groups
);
1022 void qeth_l3_remove_device_attributes(struct device
*dev
)
1024 sysfs_remove_groups(&dev
->kobj
, qeth_l3_only_attr_groups
);
1027 const struct attribute_group
*qeth_l3_attr_groups
[] = {
1028 &qeth_device_attr_group
,
1029 &qeth_device_blkt_group
,
1030 /* l3 specific, see qeth_l3_only_attr_groups: */
1031 &qeth_l3_device_attr_group
,
1032 &qeth_device_ipato_group
,
1033 &qeth_device_vipa_group
,
1034 &qeth_device_rxip_group
,