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>
15 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
16 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
18 static ssize_t
qeth_l3_dev_route_show(struct qeth_card
*card
,
19 struct qeth_routing_info
*route
, char *buf
)
21 switch (route
->type
) {
23 return sprintf(buf
, "%s\n", "primary router");
24 case SECONDARY_ROUTER
:
25 return sprintf(buf
, "%s\n", "secondary router");
26 case MULTICAST_ROUTER
:
27 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
28 return sprintf(buf
, "%s\n", "multicast router+");
30 return sprintf(buf
, "%s\n", "multicast router");
31 case PRIMARY_CONNECTOR
:
32 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
33 return sprintf(buf
, "%s\n", "primary connector+");
35 return sprintf(buf
, "%s\n", "primary connector");
36 case SECONDARY_CONNECTOR
:
37 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
38 return sprintf(buf
, "%s\n", "secondary connector+");
40 return sprintf(buf
, "%s\n", "secondary connector");
42 return sprintf(buf
, "%s\n", "no");
46 static ssize_t
qeth_l3_dev_route4_show(struct device
*dev
,
47 struct device_attribute
*attr
, char *buf
)
49 struct qeth_card
*card
= dev_get_drvdata(dev
);
54 return qeth_l3_dev_route_show(card
, &card
->options
.route4
, buf
);
57 static ssize_t
qeth_l3_dev_route_store(struct qeth_card
*card
,
58 struct qeth_routing_info
*route
, enum qeth_prot_versions prot
,
59 const char *buf
, size_t count
)
61 enum qeth_routing_types old_route_type
= route
->type
;
64 mutex_lock(&card
->conf_mutex
);
65 if (sysfs_streq(buf
, "no_router")) {
66 route
->type
= NO_ROUTER
;
67 } else if (sysfs_streq(buf
, "primary_connector")) {
68 route
->type
= PRIMARY_CONNECTOR
;
69 } else if (sysfs_streq(buf
, "secondary_connector")) {
70 route
->type
= SECONDARY_CONNECTOR
;
71 } else if (sysfs_streq(buf
, "primary_router")) {
72 route
->type
= PRIMARY_ROUTER
;
73 } else if (sysfs_streq(buf
, "secondary_router")) {
74 route
->type
= SECONDARY_ROUTER
;
75 } else if (sysfs_streq(buf
, "multicast_router")) {
76 route
->type
= MULTICAST_ROUTER
;
81 if (qeth_card_hw_is_reachable(card
) &&
82 (old_route_type
!= route
->type
)) {
83 if (prot
== QETH_PROT_IPV4
)
84 rc
= qeth_l3_setrouting_v4(card
);
85 else if (prot
== QETH_PROT_IPV6
)
86 rc
= qeth_l3_setrouting_v6(card
);
90 route
->type
= old_route_type
;
91 mutex_unlock(&card
->conf_mutex
);
92 return rc
? rc
: count
;
95 static ssize_t
qeth_l3_dev_route4_store(struct device
*dev
,
96 struct device_attribute
*attr
, const char *buf
, size_t count
)
98 struct qeth_card
*card
= dev_get_drvdata(dev
);
103 return qeth_l3_dev_route_store(card
, &card
->options
.route4
,
104 QETH_PROT_IPV4
, buf
, count
);
107 static DEVICE_ATTR(route4
, 0644, qeth_l3_dev_route4_show
,
108 qeth_l3_dev_route4_store
);
110 static ssize_t
qeth_l3_dev_route6_show(struct device
*dev
,
111 struct device_attribute
*attr
, char *buf
)
113 struct qeth_card
*card
= dev_get_drvdata(dev
);
118 return qeth_l3_dev_route_show(card
, &card
->options
.route6
, buf
);
121 static ssize_t
qeth_l3_dev_route6_store(struct device
*dev
,
122 struct device_attribute
*attr
, const char *buf
, size_t count
)
124 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_fake_broadcast_show(struct device
*dev
,
137 struct device_attribute
*attr
, char *buf
)
139 struct qeth_card
*card
= dev_get_drvdata(dev
);
144 return sprintf(buf
, "%i\n", card
->options
.fake_broadcast
? 1:0);
147 static ssize_t
qeth_l3_dev_fake_broadcast_store(struct device
*dev
,
148 struct device_attribute
*attr
, const char *buf
, size_t count
)
150 struct qeth_card
*card
= dev_get_drvdata(dev
);
157 mutex_lock(&card
->conf_mutex
);
158 if ((card
->state
!= CARD_STATE_DOWN
) &&
159 (card
->state
!= CARD_STATE_RECOVER
)) {
164 i
= simple_strtoul(buf
, &tmp
, 16);
165 if ((i
== 0) || (i
== 1))
166 card
->options
.fake_broadcast
= i
;
170 mutex_unlock(&card
->conf_mutex
);
171 return rc
? rc
: count
;
174 static DEVICE_ATTR(fake_broadcast
, 0644, qeth_l3_dev_fake_broadcast_show
,
175 qeth_l3_dev_fake_broadcast_store
);
177 static ssize_t
qeth_l3_dev_sniffer_show(struct device
*dev
,
178 struct device_attribute
*attr
, char *buf
)
180 struct qeth_card
*card
= dev_get_drvdata(dev
);
185 return sprintf(buf
, "%i\n", card
->options
.sniffer
? 1 : 0);
188 static ssize_t
qeth_l3_dev_sniffer_store(struct device
*dev
,
189 struct device_attribute
*attr
, const char *buf
, size_t count
)
191 struct qeth_card
*card
= dev_get_drvdata(dev
);
198 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
200 if (card
->options
.cq
== QETH_CQ_ENABLED
)
203 mutex_lock(&card
->conf_mutex
);
204 if ((card
->state
!= CARD_STATE_DOWN
) &&
205 (card
->state
!= CARD_STATE_RECOVER
)) {
210 rc
= kstrtoul(buf
, 16, &i
);
217 card
->options
.sniffer
= i
;
220 qdio_get_ssqd_desc(CARD_DDEV(card
), &card
->ssqd
);
221 if (card
->ssqd
.qdioac2
& QETH_SNIFF_AVAIL
) {
222 card
->options
.sniffer
= i
;
223 if (card
->qdio
.init_pool
.buf_count
!=
224 QETH_IN_BUF_COUNT_MAX
)
225 qeth_realloc_buffer_pool(card
,
226 QETH_IN_BUF_COUNT_MAX
);
234 mutex_unlock(&card
->conf_mutex
);
235 return rc
? rc
: count
;
238 static DEVICE_ATTR(sniffer
, 0644, qeth_l3_dev_sniffer_show
,
239 qeth_l3_dev_sniffer_store
);
242 static ssize_t
qeth_l3_dev_hsuid_show(struct device
*dev
,
243 struct device_attribute
*attr
, char *buf
)
245 struct qeth_card
*card
= dev_get_drvdata(dev
);
251 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
254 memcpy(tmp_hsuid
, card
->options
.hsuid
, sizeof(tmp_hsuid
));
255 EBCASC(tmp_hsuid
, 8);
256 return sprintf(buf
, "%s\n", tmp_hsuid
);
259 static ssize_t
qeth_l3_dev_hsuid_store(struct device
*dev
,
260 struct device_attribute
*attr
, const char *buf
, size_t count
)
262 struct qeth_card
*card
= dev_get_drvdata(dev
);
263 struct qeth_ipaddr
*addr
;
270 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
272 if (card
->state
!= CARD_STATE_DOWN
&&
273 card
->state
!= CARD_STATE_RECOVER
)
275 if (card
->options
.sniffer
)
277 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
)
280 tmp
= strsep((char **)&buf
, "\n");
284 if (card
->options
.hsuid
[0]) {
285 /* delete old ip address */
286 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
290 addr
->u
.a6
.addr
.s6_addr32
[0] = cpu_to_be32(0xfe800000);
291 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
292 for (i
= 8; i
< 16; i
++)
293 addr
->u
.a6
.addr
.s6_addr
[i
] =
294 card
->options
.hsuid
[i
- 8];
295 addr
->u
.a6
.pfxlen
= 0;
296 addr
->type
= QETH_IP_TYPE_NORMAL
;
298 spin_lock_bh(&card
->ip_lock
);
299 qeth_l3_delete_ip(card
, addr
);
300 spin_unlock_bh(&card
->ip_lock
);
304 if (strlen(tmp
) == 0) {
305 /* delete ip address only */
306 card
->options
.hsuid
[0] = '\0';
308 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
309 qeth_configure_cq(card
, QETH_CQ_DISABLED
);
313 if (qeth_configure_cq(card
, QETH_CQ_ENABLED
))
316 snprintf(card
->options
.hsuid
, sizeof(card
->options
.hsuid
),
318 ASCEBC(card
->options
.hsuid
, 8);
320 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
322 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
324 addr
->u
.a6
.addr
.s6_addr32
[0] = cpu_to_be32(0xfe800000);
325 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
326 for (i
= 8; i
< 16; i
++)
327 addr
->u
.a6
.addr
.s6_addr
[i
] = card
->options
.hsuid
[i
- 8];
328 addr
->u
.a6
.pfxlen
= 0;
329 addr
->type
= QETH_IP_TYPE_NORMAL
;
333 spin_lock_bh(&card
->ip_lock
);
334 qeth_l3_add_ip(card
, addr
);
335 spin_unlock_bh(&card
->ip_lock
);
341 static DEVICE_ATTR(hsuid
, 0644, qeth_l3_dev_hsuid_show
,
342 qeth_l3_dev_hsuid_store
);
345 static struct attribute
*qeth_l3_device_attrs
[] = {
346 &dev_attr_route4
.attr
,
347 &dev_attr_route6
.attr
,
348 &dev_attr_fake_broadcast
.attr
,
349 &dev_attr_sniffer
.attr
,
350 &dev_attr_hsuid
.attr
,
354 static const struct attribute_group qeth_l3_device_attr_group
= {
355 .attrs
= qeth_l3_device_attrs
,
358 static ssize_t
qeth_l3_dev_ipato_enable_show(struct device
*dev
,
359 struct device_attribute
*attr
, char *buf
)
361 struct qeth_card
*card
= dev_get_drvdata(dev
);
366 return sprintf(buf
, "%i\n", card
->ipato
.enabled
? 1:0);
369 static ssize_t
qeth_l3_dev_ipato_enable_store(struct device
*dev
,
370 struct device_attribute
*attr
, const char *buf
, size_t count
)
372 struct qeth_card
*card
= dev_get_drvdata(dev
);
373 struct qeth_ipaddr
*addr
;
379 mutex_lock(&card
->conf_mutex
);
380 if ((card
->state
!= CARD_STATE_DOWN
) &&
381 (card
->state
!= CARD_STATE_RECOVER
)) {
386 if (sysfs_streq(buf
, "toggle")) {
387 card
->ipato
.enabled
= (card
->ipato
.enabled
)? 0 : 1;
388 } else if (sysfs_streq(buf
, "1")) {
389 card
->ipato
.enabled
= 1;
390 hash_for_each(card
->ip_htable
, i
, addr
, hnode
) {
391 if ((addr
->type
== QETH_IP_TYPE_NORMAL
) &&
392 qeth_l3_is_addr_covered_by_ipato(card
, addr
))
394 QETH_IPA_SETIP_TAKEOVER_FLAG
;
396 } else if (sysfs_streq(buf
, "0")) {
397 card
->ipato
.enabled
= 0;
398 hash_for_each(card
->ip_htable
, i
, addr
, hnode
) {
399 if (addr
->set_flags
&
400 QETH_IPA_SETIP_TAKEOVER_FLAG
)
402 ~QETH_IPA_SETIP_TAKEOVER_FLAG
;
407 mutex_unlock(&card
->conf_mutex
);
408 return rc
? rc
: count
;
411 static QETH_DEVICE_ATTR(ipato_enable
, enable
, 0644,
412 qeth_l3_dev_ipato_enable_show
,
413 qeth_l3_dev_ipato_enable_store
);
415 static ssize_t
qeth_l3_dev_ipato_invert4_show(struct device
*dev
,
416 struct device_attribute
*attr
, char *buf
)
418 struct qeth_card
*card
= dev_get_drvdata(dev
);
423 return sprintf(buf
, "%i\n", card
->ipato
.invert4
? 1:0);
426 static ssize_t
qeth_l3_dev_ipato_invert4_store(struct device
*dev
,
427 struct device_attribute
*attr
,
428 const char *buf
, size_t count
)
430 struct qeth_card
*card
= dev_get_drvdata(dev
);
436 mutex_lock(&card
->conf_mutex
);
437 if (sysfs_streq(buf
, "toggle"))
438 card
->ipato
.invert4
= (card
->ipato
.invert4
)? 0 : 1;
439 else if (sysfs_streq(buf
, "1"))
440 card
->ipato
.invert4
= 1;
441 else if (sysfs_streq(buf
, "0"))
442 card
->ipato
.invert4
= 0;
445 mutex_unlock(&card
->conf_mutex
);
446 return rc
? rc
: count
;
449 static QETH_DEVICE_ATTR(ipato_invert4
, invert4
, 0644,
450 qeth_l3_dev_ipato_invert4_show
,
451 qeth_l3_dev_ipato_invert4_store
);
453 static ssize_t
qeth_l3_dev_ipato_add_show(char *buf
, struct qeth_card
*card
,
454 enum qeth_prot_versions proto
)
456 struct qeth_ipato_entry
*ipatoe
;
458 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
461 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
462 /* add strlen for "/<mask>\n" */
463 entry_len
+= (proto
== QETH_PROT_IPV4
)? 5 : 6;
464 spin_lock_bh(&card
->ip_lock
);
465 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
466 if (ipatoe
->proto
!= proto
)
468 /* String must not be longer than PAGE_SIZE. So we check if
469 * string length gets near PAGE_SIZE. Then we can savely display
470 * the next IPv6 address (worst case, compared to IPv4) */
471 if ((PAGE_SIZE
- i
) <= entry_len
)
473 qeth_l3_ipaddr_to_string(proto
, ipatoe
->addr
, addr_str
);
474 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
,
475 "%s/%i\n", addr_str
, ipatoe
->mask_bits
);
477 spin_unlock_bh(&card
->ip_lock
);
478 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
483 static ssize_t
qeth_l3_dev_ipato_add4_show(struct device
*dev
,
484 struct device_attribute
*attr
, char *buf
)
486 struct qeth_card
*card
= dev_get_drvdata(dev
);
491 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV4
);
494 static int qeth_l3_parse_ipatoe(const char *buf
, enum qeth_prot_versions proto
,
495 u8
*addr
, int *mask_bits
)
497 const char *start
, *end
;
499 char buffer
[40] = {0, };
502 /* get address string */
503 end
= strchr(start
, '/');
504 if (!end
|| (end
- start
>= 40)) {
507 strncpy(buffer
, start
, end
- start
);
508 if (qeth_l3_string_to_ipaddr(buffer
, proto
, addr
)) {
512 *mask_bits
= simple_strtoul(start
, &tmp
, 10);
513 if (!strlen(start
) ||
515 (*mask_bits
> ((proto
== QETH_PROT_IPV4
) ? 32 : 128))) {
521 static ssize_t
qeth_l3_dev_ipato_add_store(const char *buf
, size_t count
,
522 struct qeth_card
*card
, enum qeth_prot_versions proto
)
524 struct qeth_ipato_entry
*ipatoe
;
529 mutex_lock(&card
->conf_mutex
);
530 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
534 ipatoe
= kzalloc(sizeof(struct qeth_ipato_entry
), GFP_KERNEL
);
539 ipatoe
->proto
= proto
;
540 memcpy(ipatoe
->addr
, addr
, (proto
== QETH_PROT_IPV4
)? 4:16);
541 ipatoe
->mask_bits
= mask_bits
;
543 rc
= qeth_l3_add_ipato_entry(card
, ipatoe
);
547 mutex_unlock(&card
->conf_mutex
);
548 return rc
? rc
: count
;
551 static ssize_t
qeth_l3_dev_ipato_add4_store(struct device
*dev
,
552 struct device_attribute
*attr
, const char *buf
, size_t count
)
554 struct qeth_card
*card
= dev_get_drvdata(dev
);
559 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
562 static QETH_DEVICE_ATTR(ipato_add4
, add4
, 0644,
563 qeth_l3_dev_ipato_add4_show
,
564 qeth_l3_dev_ipato_add4_store
);
566 static ssize_t
qeth_l3_dev_ipato_del_store(const char *buf
, size_t count
,
567 struct qeth_card
*card
, enum qeth_prot_versions proto
)
573 mutex_lock(&card
->conf_mutex
);
574 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
576 qeth_l3_del_ipato_entry(card
, proto
, addr
, mask_bits
);
577 mutex_unlock(&card
->conf_mutex
);
578 return rc
? rc
: count
;
581 static ssize_t
qeth_l3_dev_ipato_del4_store(struct device
*dev
,
582 struct device_attribute
*attr
, const char *buf
, size_t count
)
584 struct qeth_card
*card
= dev_get_drvdata(dev
);
589 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
592 static QETH_DEVICE_ATTR(ipato_del4
, del4
, 0200, NULL
,
593 qeth_l3_dev_ipato_del4_store
);
595 static ssize_t
qeth_l3_dev_ipato_invert6_show(struct device
*dev
,
596 struct device_attribute
*attr
, char *buf
)
598 struct qeth_card
*card
= dev_get_drvdata(dev
);
603 return sprintf(buf
, "%i\n", card
->ipato
.invert6
? 1:0);
606 static ssize_t
qeth_l3_dev_ipato_invert6_store(struct device
*dev
,
607 struct device_attribute
*attr
, const char *buf
, size_t count
)
609 struct qeth_card
*card
= dev_get_drvdata(dev
);
615 mutex_lock(&card
->conf_mutex
);
616 if (sysfs_streq(buf
, "toggle"))
617 card
->ipato
.invert6
= (card
->ipato
.invert6
)? 0 : 1;
618 else if (sysfs_streq(buf
, "1"))
619 card
->ipato
.invert6
= 1;
620 else if (sysfs_streq(buf
, "0"))
621 card
->ipato
.invert6
= 0;
624 mutex_unlock(&card
->conf_mutex
);
625 return rc
? rc
: count
;
628 static QETH_DEVICE_ATTR(ipato_invert6
, invert6
, 0644,
629 qeth_l3_dev_ipato_invert6_show
,
630 qeth_l3_dev_ipato_invert6_store
);
633 static ssize_t
qeth_l3_dev_ipato_add6_show(struct device
*dev
,
634 struct device_attribute
*attr
, char *buf
)
636 struct qeth_card
*card
= dev_get_drvdata(dev
);
641 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV6
);
644 static ssize_t
qeth_l3_dev_ipato_add6_store(struct device
*dev
,
645 struct device_attribute
*attr
, const char *buf
, size_t count
)
647 struct qeth_card
*card
= dev_get_drvdata(dev
);
652 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
655 static QETH_DEVICE_ATTR(ipato_add6
, add6
, 0644,
656 qeth_l3_dev_ipato_add6_show
,
657 qeth_l3_dev_ipato_add6_store
);
659 static ssize_t
qeth_l3_dev_ipato_del6_store(struct device
*dev
,
660 struct device_attribute
*attr
, const char *buf
, size_t count
)
662 struct qeth_card
*card
= dev_get_drvdata(dev
);
667 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
670 static QETH_DEVICE_ATTR(ipato_del6
, del6
, 0200, NULL
,
671 qeth_l3_dev_ipato_del6_store
);
673 static struct attribute
*qeth_ipato_device_attrs
[] = {
674 &dev_attr_ipato_enable
.attr
,
675 &dev_attr_ipato_invert4
.attr
,
676 &dev_attr_ipato_add4
.attr
,
677 &dev_attr_ipato_del4
.attr
,
678 &dev_attr_ipato_invert6
.attr
,
679 &dev_attr_ipato_add6
.attr
,
680 &dev_attr_ipato_del6
.attr
,
684 static const struct attribute_group qeth_device_ipato_group
= {
685 .name
= "ipa_takeover",
686 .attrs
= qeth_ipato_device_attrs
,
689 static ssize_t
qeth_l3_dev_vipa_add_show(char *buf
, struct qeth_card
*card
,
690 enum qeth_prot_versions proto
)
692 struct qeth_ipaddr
*ipaddr
;
695 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
698 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
699 entry_len
+= 2; /* \n + terminator */
700 spin_lock_bh(&card
->ip_lock
);
701 hash_for_each(card
->ip_htable
, i
, ipaddr
, hnode
) {
702 if (ipaddr
->proto
!= proto
)
704 if (ipaddr
->type
!= QETH_IP_TYPE_VIPA
)
706 /* String must not be longer than PAGE_SIZE. So we check if
707 * string length gets near PAGE_SIZE. Then we can savely display
708 * the next IPv6 address (worst case, compared to IPv4) */
709 if ((PAGE_SIZE
- str_len
) <= entry_len
)
711 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
713 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "%s\n",
716 spin_unlock_bh(&card
->ip_lock
);
717 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "\n");
722 static ssize_t
qeth_l3_dev_vipa_add4_show(struct device
*dev
,
723 struct device_attribute
*attr
, char *buf
)
725 struct qeth_card
*card
= dev_get_drvdata(dev
);
730 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV4
);
733 static int qeth_l3_parse_vipae(const char *buf
, enum qeth_prot_versions proto
,
736 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
742 static ssize_t
qeth_l3_dev_vipa_add_store(const char *buf
, size_t count
,
743 struct qeth_card
*card
, enum qeth_prot_versions proto
)
748 mutex_lock(&card
->conf_mutex
);
749 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
751 rc
= qeth_l3_add_vipa(card
, proto
, addr
);
752 mutex_unlock(&card
->conf_mutex
);
753 return rc
? rc
: count
;
756 static ssize_t
qeth_l3_dev_vipa_add4_store(struct device
*dev
,
757 struct device_attribute
*attr
, const char *buf
, size_t count
)
759 struct qeth_card
*card
= dev_get_drvdata(dev
);
764 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
767 static QETH_DEVICE_ATTR(vipa_add4
, add4
, 0644,
768 qeth_l3_dev_vipa_add4_show
,
769 qeth_l3_dev_vipa_add4_store
);
771 static ssize_t
qeth_l3_dev_vipa_del_store(const char *buf
, size_t count
,
772 struct qeth_card
*card
, enum qeth_prot_versions proto
)
777 mutex_lock(&card
->conf_mutex
);
778 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
780 qeth_l3_del_vipa(card
, proto
, addr
);
781 mutex_unlock(&card
->conf_mutex
);
782 return rc
? rc
: count
;
785 static ssize_t
qeth_l3_dev_vipa_del4_store(struct device
*dev
,
786 struct device_attribute
*attr
, const char *buf
, size_t count
)
788 struct qeth_card
*card
= dev_get_drvdata(dev
);
793 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
796 static QETH_DEVICE_ATTR(vipa_del4
, del4
, 0200, NULL
,
797 qeth_l3_dev_vipa_del4_store
);
799 static ssize_t
qeth_l3_dev_vipa_add6_show(struct device
*dev
,
800 struct device_attribute
*attr
, char *buf
)
802 struct qeth_card
*card
= dev_get_drvdata(dev
);
807 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV6
);
810 static ssize_t
qeth_l3_dev_vipa_add6_store(struct device
*dev
,
811 struct device_attribute
*attr
, const char *buf
, size_t count
)
813 struct qeth_card
*card
= dev_get_drvdata(dev
);
818 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
821 static QETH_DEVICE_ATTR(vipa_add6
, add6
, 0644,
822 qeth_l3_dev_vipa_add6_show
,
823 qeth_l3_dev_vipa_add6_store
);
825 static ssize_t
qeth_l3_dev_vipa_del6_store(struct device
*dev
,
826 struct device_attribute
*attr
, const char *buf
, size_t count
)
828 struct qeth_card
*card
= dev_get_drvdata(dev
);
833 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
836 static QETH_DEVICE_ATTR(vipa_del6
, del6
, 0200, NULL
,
837 qeth_l3_dev_vipa_del6_store
);
839 static struct attribute
*qeth_vipa_device_attrs
[] = {
840 &dev_attr_vipa_add4
.attr
,
841 &dev_attr_vipa_del4
.attr
,
842 &dev_attr_vipa_add6
.attr
,
843 &dev_attr_vipa_del6
.attr
,
847 static const struct attribute_group qeth_device_vipa_group
= {
849 .attrs
= qeth_vipa_device_attrs
,
852 static ssize_t
qeth_l3_dev_rxip_add_show(char *buf
, struct qeth_card
*card
,
853 enum qeth_prot_versions proto
)
855 struct qeth_ipaddr
*ipaddr
;
858 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
861 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
862 entry_len
+= 2; /* \n + terminator */
863 spin_lock_bh(&card
->ip_lock
);
864 hash_for_each(card
->ip_htable
, i
, ipaddr
, hnode
) {
865 if (ipaddr
->proto
!= proto
)
867 if (ipaddr
->type
!= QETH_IP_TYPE_RXIP
)
869 /* String must not be longer than PAGE_SIZE. So we check if
870 * string length gets near PAGE_SIZE. Then we can savely display
871 * the next IPv6 address (worst case, compared to IPv4) */
872 if ((PAGE_SIZE
- str_len
) <= entry_len
)
874 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
876 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "%s\n",
879 spin_unlock_bh(&card
->ip_lock
);
880 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "\n");
885 static ssize_t
qeth_l3_dev_rxip_add4_show(struct device
*dev
,
886 struct device_attribute
*attr
, char *buf
)
888 struct qeth_card
*card
= dev_get_drvdata(dev
);
893 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV4
);
896 static int qeth_l3_parse_rxipe(const char *buf
, enum qeth_prot_versions proto
,
900 struct in6_addr ipv6_addr
;
902 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
905 if (proto
== QETH_PROT_IPV4
) {
906 memcpy(&ipv4_addr
, addr
, sizeof(ipv4_addr
));
907 if (ipv4_is_multicast(ipv4_addr
)) {
908 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
911 } else if (proto
== QETH_PROT_IPV6
) {
912 memcpy(&ipv6_addr
, addr
, sizeof(ipv6_addr
));
913 if (ipv6_addr_is_multicast(&ipv6_addr
)) {
914 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
922 static ssize_t
qeth_l3_dev_rxip_add_store(const char *buf
, size_t count
,
923 struct qeth_card
*card
, enum qeth_prot_versions proto
)
928 mutex_lock(&card
->conf_mutex
);
929 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
931 rc
= qeth_l3_add_rxip(card
, proto
, addr
);
932 mutex_unlock(&card
->conf_mutex
);
933 return rc
? rc
: count
;
936 static ssize_t
qeth_l3_dev_rxip_add4_store(struct device
*dev
,
937 struct device_attribute
*attr
, const char *buf
, size_t count
)
939 struct qeth_card
*card
= dev_get_drvdata(dev
);
944 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
947 static QETH_DEVICE_ATTR(rxip_add4
, add4
, 0644,
948 qeth_l3_dev_rxip_add4_show
,
949 qeth_l3_dev_rxip_add4_store
);
951 static ssize_t
qeth_l3_dev_rxip_del_store(const char *buf
, size_t count
,
952 struct qeth_card
*card
, enum qeth_prot_versions proto
)
957 mutex_lock(&card
->conf_mutex
);
958 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
960 qeth_l3_del_rxip(card
, proto
, addr
);
961 mutex_unlock(&card
->conf_mutex
);
962 return rc
? rc
: count
;
965 static ssize_t
qeth_l3_dev_rxip_del4_store(struct device
*dev
,
966 struct device_attribute
*attr
, const char *buf
, size_t count
)
968 struct qeth_card
*card
= dev_get_drvdata(dev
);
973 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
976 static QETH_DEVICE_ATTR(rxip_del4
, del4
, 0200, NULL
,
977 qeth_l3_dev_rxip_del4_store
);
979 static ssize_t
qeth_l3_dev_rxip_add6_show(struct device
*dev
,
980 struct device_attribute
*attr
, char *buf
)
982 struct qeth_card
*card
= dev_get_drvdata(dev
);
987 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV6
);
990 static ssize_t
qeth_l3_dev_rxip_add6_store(struct device
*dev
,
991 struct device_attribute
*attr
, const char *buf
, size_t count
)
993 struct qeth_card
*card
= dev_get_drvdata(dev
);
998 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
1001 static QETH_DEVICE_ATTR(rxip_add6
, add6
, 0644,
1002 qeth_l3_dev_rxip_add6_show
,
1003 qeth_l3_dev_rxip_add6_store
);
1005 static ssize_t
qeth_l3_dev_rxip_del6_store(struct device
*dev
,
1006 struct device_attribute
*attr
, const char *buf
, size_t count
)
1008 struct qeth_card
*card
= dev_get_drvdata(dev
);
1013 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
1016 static QETH_DEVICE_ATTR(rxip_del6
, del6
, 0200, NULL
,
1017 qeth_l3_dev_rxip_del6_store
);
1019 static struct attribute
*qeth_rxip_device_attrs
[] = {
1020 &dev_attr_rxip_add4
.attr
,
1021 &dev_attr_rxip_del4
.attr
,
1022 &dev_attr_rxip_add6
.attr
,
1023 &dev_attr_rxip_del6
.attr
,
1027 static const struct attribute_group qeth_device_rxip_group
= {
1029 .attrs
= qeth_rxip_device_attrs
,
1032 int qeth_l3_create_device_attributes(struct device
*dev
)
1036 ret
= sysfs_create_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1040 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_ipato_group
);
1042 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1046 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_vipa_group
);
1048 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1049 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1053 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_rxip_group
);
1055 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1056 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1057 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1063 void qeth_l3_remove_device_attributes(struct device
*dev
)
1065 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1066 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1067 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1068 sysfs_remove_group(&dev
->kobj
, &qeth_device_rxip_group
);
1071 const struct attribute_group
*qeth_l3_attr_groups
[] = {
1072 &qeth_device_attr_group
,
1073 &qeth_device_blkt_group
,
1074 /* l3 specific, see l3_{create,remove}_device_attributes(): */
1075 &qeth_l3_device_attr_group
,
1076 &qeth_device_ipato_group
,
1077 &qeth_device_vipa_group
,
1078 &qeth_device_rxip_group
,