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
);
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 enable
= !card
->ipato
.enabled
;
388 } else if (kstrtobool(buf
, &enable
)) {
393 if (card
->ipato
.enabled
!= enable
) {
394 card
->ipato
.enabled
= enable
;
395 spin_lock_bh(&card
->ip_lock
);
396 qeth_l3_update_ipato(card
);
397 spin_unlock_bh(&card
->ip_lock
);
400 mutex_unlock(&card
->conf_mutex
);
401 return rc
? rc
: count
;
404 static QETH_DEVICE_ATTR(ipato_enable
, enable
, 0644,
405 qeth_l3_dev_ipato_enable_show
,
406 qeth_l3_dev_ipato_enable_store
);
408 static ssize_t
qeth_l3_dev_ipato_invert4_show(struct device
*dev
,
409 struct device_attribute
*attr
, char *buf
)
411 struct qeth_card
*card
= dev_get_drvdata(dev
);
416 return sprintf(buf
, "%i\n", card
->ipato
.invert4
? 1:0);
419 static ssize_t
qeth_l3_dev_ipato_invert4_store(struct device
*dev
,
420 struct device_attribute
*attr
,
421 const char *buf
, size_t count
)
423 struct qeth_card
*card
= dev_get_drvdata(dev
);
430 mutex_lock(&card
->conf_mutex
);
431 if (sysfs_streq(buf
, "toggle")) {
432 invert
= !card
->ipato
.invert4
;
433 } else if (kstrtobool(buf
, &invert
)) {
438 if (card
->ipato
.invert4
!= invert
) {
439 card
->ipato
.invert4
= invert
;
440 spin_lock_bh(&card
->ip_lock
);
441 qeth_l3_update_ipato(card
);
442 spin_unlock_bh(&card
->ip_lock
);
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
);
616 mutex_lock(&card
->conf_mutex
);
617 if (sysfs_streq(buf
, "toggle")) {
618 invert
= !card
->ipato
.invert6
;
619 } else if (kstrtobool(buf
, &invert
)) {
624 if (card
->ipato
.invert6
!= invert
) {
625 card
->ipato
.invert6
= invert
;
626 spin_lock_bh(&card
->ip_lock
);
627 qeth_l3_update_ipato(card
);
628 spin_unlock_bh(&card
->ip_lock
);
631 mutex_unlock(&card
->conf_mutex
);
632 return rc
? rc
: count
;
635 static QETH_DEVICE_ATTR(ipato_invert6
, invert6
, 0644,
636 qeth_l3_dev_ipato_invert6_show
,
637 qeth_l3_dev_ipato_invert6_store
);
640 static ssize_t
qeth_l3_dev_ipato_add6_show(struct device
*dev
,
641 struct device_attribute
*attr
, char *buf
)
643 struct qeth_card
*card
= dev_get_drvdata(dev
);
648 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV6
);
651 static ssize_t
qeth_l3_dev_ipato_add6_store(struct device
*dev
,
652 struct device_attribute
*attr
, const char *buf
, size_t count
)
654 struct qeth_card
*card
= dev_get_drvdata(dev
);
659 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
662 static QETH_DEVICE_ATTR(ipato_add6
, add6
, 0644,
663 qeth_l3_dev_ipato_add6_show
,
664 qeth_l3_dev_ipato_add6_store
);
666 static ssize_t
qeth_l3_dev_ipato_del6_store(struct device
*dev
,
667 struct device_attribute
*attr
, const char *buf
, size_t count
)
669 struct qeth_card
*card
= dev_get_drvdata(dev
);
674 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
677 static QETH_DEVICE_ATTR(ipato_del6
, del6
, 0200, NULL
,
678 qeth_l3_dev_ipato_del6_store
);
680 static struct attribute
*qeth_ipato_device_attrs
[] = {
681 &dev_attr_ipato_enable
.attr
,
682 &dev_attr_ipato_invert4
.attr
,
683 &dev_attr_ipato_add4
.attr
,
684 &dev_attr_ipato_del4
.attr
,
685 &dev_attr_ipato_invert6
.attr
,
686 &dev_attr_ipato_add6
.attr
,
687 &dev_attr_ipato_del6
.attr
,
691 static const struct attribute_group qeth_device_ipato_group
= {
692 .name
= "ipa_takeover",
693 .attrs
= qeth_ipato_device_attrs
,
696 static ssize_t
qeth_l3_dev_vipa_add_show(char *buf
, struct qeth_card
*card
,
697 enum qeth_prot_versions proto
)
699 struct qeth_ipaddr
*ipaddr
;
702 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
705 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
706 entry_len
+= 2; /* \n + terminator */
707 spin_lock_bh(&card
->ip_lock
);
708 hash_for_each(card
->ip_htable
, i
, ipaddr
, hnode
) {
709 if (ipaddr
->proto
!= proto
)
711 if (ipaddr
->type
!= QETH_IP_TYPE_VIPA
)
713 /* String must not be longer than PAGE_SIZE. So we check if
714 * string length gets near PAGE_SIZE. Then we can savely display
715 * the next IPv6 address (worst case, compared to IPv4) */
716 if ((PAGE_SIZE
- str_len
) <= entry_len
)
718 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
720 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "%s\n",
723 spin_unlock_bh(&card
->ip_lock
);
724 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "\n");
729 static ssize_t
qeth_l3_dev_vipa_add4_show(struct device
*dev
,
730 struct device_attribute
*attr
, char *buf
)
732 struct qeth_card
*card
= dev_get_drvdata(dev
);
737 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV4
);
740 static int qeth_l3_parse_vipae(const char *buf
, enum qeth_prot_versions proto
,
743 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
749 static ssize_t
qeth_l3_dev_vipa_add_store(const char *buf
, size_t count
,
750 struct qeth_card
*card
, enum qeth_prot_versions proto
)
755 mutex_lock(&card
->conf_mutex
);
756 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
758 rc
= qeth_l3_add_vipa(card
, proto
, addr
);
759 mutex_unlock(&card
->conf_mutex
);
760 return rc
? rc
: count
;
763 static ssize_t
qeth_l3_dev_vipa_add4_store(struct device
*dev
,
764 struct device_attribute
*attr
, const char *buf
, size_t count
)
766 struct qeth_card
*card
= dev_get_drvdata(dev
);
771 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
774 static QETH_DEVICE_ATTR(vipa_add4
, add4
, 0644,
775 qeth_l3_dev_vipa_add4_show
,
776 qeth_l3_dev_vipa_add4_store
);
778 static ssize_t
qeth_l3_dev_vipa_del_store(const char *buf
, size_t count
,
779 struct qeth_card
*card
, enum qeth_prot_versions proto
)
784 mutex_lock(&card
->conf_mutex
);
785 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
787 qeth_l3_del_vipa(card
, proto
, addr
);
788 mutex_unlock(&card
->conf_mutex
);
789 return rc
? rc
: count
;
792 static ssize_t
qeth_l3_dev_vipa_del4_store(struct device
*dev
,
793 struct device_attribute
*attr
, const char *buf
, size_t count
)
795 struct qeth_card
*card
= dev_get_drvdata(dev
);
800 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
803 static QETH_DEVICE_ATTR(vipa_del4
, del4
, 0200, NULL
,
804 qeth_l3_dev_vipa_del4_store
);
806 static ssize_t
qeth_l3_dev_vipa_add6_show(struct device
*dev
,
807 struct device_attribute
*attr
, char *buf
)
809 struct qeth_card
*card
= dev_get_drvdata(dev
);
814 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV6
);
817 static ssize_t
qeth_l3_dev_vipa_add6_store(struct device
*dev
,
818 struct device_attribute
*attr
, const char *buf
, size_t count
)
820 struct qeth_card
*card
= dev_get_drvdata(dev
);
825 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
828 static QETH_DEVICE_ATTR(vipa_add6
, add6
, 0644,
829 qeth_l3_dev_vipa_add6_show
,
830 qeth_l3_dev_vipa_add6_store
);
832 static ssize_t
qeth_l3_dev_vipa_del6_store(struct device
*dev
,
833 struct device_attribute
*attr
, const char *buf
, size_t count
)
835 struct qeth_card
*card
= dev_get_drvdata(dev
);
840 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
843 static QETH_DEVICE_ATTR(vipa_del6
, del6
, 0200, NULL
,
844 qeth_l3_dev_vipa_del6_store
);
846 static struct attribute
*qeth_vipa_device_attrs
[] = {
847 &dev_attr_vipa_add4
.attr
,
848 &dev_attr_vipa_del4
.attr
,
849 &dev_attr_vipa_add6
.attr
,
850 &dev_attr_vipa_del6
.attr
,
854 static const struct attribute_group qeth_device_vipa_group
= {
856 .attrs
= qeth_vipa_device_attrs
,
859 static ssize_t
qeth_l3_dev_rxip_add_show(char *buf
, struct qeth_card
*card
,
860 enum qeth_prot_versions proto
)
862 struct qeth_ipaddr
*ipaddr
;
865 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
868 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
869 entry_len
+= 2; /* \n + terminator */
870 spin_lock_bh(&card
->ip_lock
);
871 hash_for_each(card
->ip_htable
, i
, ipaddr
, hnode
) {
872 if (ipaddr
->proto
!= proto
)
874 if (ipaddr
->type
!= QETH_IP_TYPE_RXIP
)
876 /* String must not be longer than PAGE_SIZE. So we check if
877 * string length gets near PAGE_SIZE. Then we can savely display
878 * the next IPv6 address (worst case, compared to IPv4) */
879 if ((PAGE_SIZE
- str_len
) <= entry_len
)
881 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
883 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "%s\n",
886 spin_unlock_bh(&card
->ip_lock
);
887 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "\n");
892 static ssize_t
qeth_l3_dev_rxip_add4_show(struct device
*dev
,
893 struct device_attribute
*attr
, char *buf
)
895 struct qeth_card
*card
= dev_get_drvdata(dev
);
900 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV4
);
903 static int qeth_l3_parse_rxipe(const char *buf
, enum qeth_prot_versions proto
,
907 struct in6_addr ipv6_addr
;
909 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
912 if (proto
== QETH_PROT_IPV4
) {
913 memcpy(&ipv4_addr
, addr
, sizeof(ipv4_addr
));
914 if (ipv4_is_multicast(ipv4_addr
)) {
915 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
918 } else if (proto
== QETH_PROT_IPV6
) {
919 memcpy(&ipv6_addr
, addr
, sizeof(ipv6_addr
));
920 if (ipv6_addr_is_multicast(&ipv6_addr
)) {
921 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
929 static ssize_t
qeth_l3_dev_rxip_add_store(const char *buf
, size_t count
,
930 struct qeth_card
*card
, enum qeth_prot_versions proto
)
935 mutex_lock(&card
->conf_mutex
);
936 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
938 rc
= qeth_l3_add_rxip(card
, proto
, addr
);
939 mutex_unlock(&card
->conf_mutex
);
940 return rc
? rc
: count
;
943 static ssize_t
qeth_l3_dev_rxip_add4_store(struct device
*dev
,
944 struct device_attribute
*attr
, const char *buf
, size_t count
)
946 struct qeth_card
*card
= dev_get_drvdata(dev
);
951 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
954 static QETH_DEVICE_ATTR(rxip_add4
, add4
, 0644,
955 qeth_l3_dev_rxip_add4_show
,
956 qeth_l3_dev_rxip_add4_store
);
958 static ssize_t
qeth_l3_dev_rxip_del_store(const char *buf
, size_t count
,
959 struct qeth_card
*card
, enum qeth_prot_versions proto
)
964 mutex_lock(&card
->conf_mutex
);
965 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
967 qeth_l3_del_rxip(card
, proto
, addr
);
968 mutex_unlock(&card
->conf_mutex
);
969 return rc
? rc
: count
;
972 static ssize_t
qeth_l3_dev_rxip_del4_store(struct device
*dev
,
973 struct device_attribute
*attr
, const char *buf
, size_t count
)
975 struct qeth_card
*card
= dev_get_drvdata(dev
);
980 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
983 static QETH_DEVICE_ATTR(rxip_del4
, del4
, 0200, NULL
,
984 qeth_l3_dev_rxip_del4_store
);
986 static ssize_t
qeth_l3_dev_rxip_add6_show(struct device
*dev
,
987 struct device_attribute
*attr
, char *buf
)
989 struct qeth_card
*card
= dev_get_drvdata(dev
);
994 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV6
);
997 static ssize_t
qeth_l3_dev_rxip_add6_store(struct device
*dev
,
998 struct device_attribute
*attr
, const char *buf
, size_t count
)
1000 struct qeth_card
*card
= dev_get_drvdata(dev
);
1005 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
1008 static QETH_DEVICE_ATTR(rxip_add6
, add6
, 0644,
1009 qeth_l3_dev_rxip_add6_show
,
1010 qeth_l3_dev_rxip_add6_store
);
1012 static ssize_t
qeth_l3_dev_rxip_del6_store(struct device
*dev
,
1013 struct device_attribute
*attr
, const char *buf
, size_t count
)
1015 struct qeth_card
*card
= dev_get_drvdata(dev
);
1020 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
1023 static QETH_DEVICE_ATTR(rxip_del6
, del6
, 0200, NULL
,
1024 qeth_l3_dev_rxip_del6_store
);
1026 static struct attribute
*qeth_rxip_device_attrs
[] = {
1027 &dev_attr_rxip_add4
.attr
,
1028 &dev_attr_rxip_del4
.attr
,
1029 &dev_attr_rxip_add6
.attr
,
1030 &dev_attr_rxip_del6
.attr
,
1034 static const struct attribute_group qeth_device_rxip_group
= {
1036 .attrs
= qeth_rxip_device_attrs
,
1039 static const struct attribute_group
*qeth_l3_only_attr_groups
[] = {
1040 &qeth_l3_device_attr_group
,
1041 &qeth_device_ipato_group
,
1042 &qeth_device_vipa_group
,
1043 &qeth_device_rxip_group
,
1047 int qeth_l3_create_device_attributes(struct device
*dev
)
1049 return sysfs_create_groups(&dev
->kobj
, qeth_l3_only_attr_groups
);
1052 void qeth_l3_remove_device_attributes(struct device
*dev
)
1054 sysfs_remove_groups(&dev
->kobj
, qeth_l3_only_attr_groups
);
1057 const struct attribute_group
*qeth_l3_attr_groups
[] = {
1058 &qeth_device_attr_group
,
1059 &qeth_device_blkt_group
,
1060 /* l3 specific, see qeth_l3_only_attr_groups: */
1061 &qeth_l3_device_attr_group
,
1062 &qeth_device_ipato_group
,
1063 &qeth_device_vipa_group
,
1064 &qeth_device_rxip_group
,