2 * drivers/s390/net/qeth_l3_sys.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
11 #include <linux/slab.h>
12 #include <asm/ebcdic.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
;
65 tmp
= strsep((char **) &buf
, "\n");
66 mutex_lock(&card
->conf_mutex
);
67 if (!strcmp(tmp
, "no_router")) {
68 route
->type
= NO_ROUTER
;
69 } else if (!strcmp(tmp
, "primary_connector")) {
70 route
->type
= PRIMARY_CONNECTOR
;
71 } else if (!strcmp(tmp
, "secondary_connector")) {
72 route
->type
= SECONDARY_CONNECTOR
;
73 } else if (!strcmp(tmp
, "primary_router")) {
74 route
->type
= PRIMARY_ROUTER
;
75 } else if (!strcmp(tmp
, "secondary_router")) {
76 route
->type
= SECONDARY_ROUTER
;
77 } else if (!strcmp(tmp
, "multicast_router")) {
78 route
->type
= MULTICAST_ROUTER
;
83 if (((card
->state
== CARD_STATE_SOFTSETUP
) ||
84 (card
->state
== CARD_STATE_UP
)) &&
85 (old_route_type
!= route
->type
)) {
86 if (prot
== QETH_PROT_IPV4
)
87 rc
= qeth_l3_setrouting_v4(card
);
88 else if (prot
== QETH_PROT_IPV6
)
89 rc
= qeth_l3_setrouting_v6(card
);
92 mutex_unlock(&card
->conf_mutex
);
93 return rc
? rc
: count
;
96 static ssize_t
qeth_l3_dev_route4_store(struct device
*dev
,
97 struct device_attribute
*attr
, const char *buf
, size_t count
)
99 struct qeth_card
*card
= dev_get_drvdata(dev
);
104 return qeth_l3_dev_route_store(card
, &card
->options
.route4
,
105 QETH_PROT_IPV4
, buf
, count
);
108 static DEVICE_ATTR(route4
, 0644, qeth_l3_dev_route4_show
,
109 qeth_l3_dev_route4_store
);
111 static ssize_t
qeth_l3_dev_route6_show(struct device
*dev
,
112 struct device_attribute
*attr
, char *buf
)
114 struct qeth_card
*card
= dev_get_drvdata(dev
);
119 return qeth_l3_dev_route_show(card
, &card
->options
.route6
, buf
);
122 static ssize_t
qeth_l3_dev_route6_store(struct device
*dev
,
123 struct device_attribute
*attr
, const char *buf
, size_t count
)
125 struct qeth_card
*card
= dev_get_drvdata(dev
);
130 return qeth_l3_dev_route_store(card
, &card
->options
.route6
,
131 QETH_PROT_IPV6
, buf
, count
);
134 static DEVICE_ATTR(route6
, 0644, qeth_l3_dev_route6_show
,
135 qeth_l3_dev_route6_store
);
137 static ssize_t
qeth_l3_dev_fake_broadcast_show(struct device
*dev
,
138 struct device_attribute
*attr
, char *buf
)
140 struct qeth_card
*card
= dev_get_drvdata(dev
);
145 return sprintf(buf
, "%i\n", card
->options
.fake_broadcast
? 1:0);
148 static ssize_t
qeth_l3_dev_fake_broadcast_store(struct device
*dev
,
149 struct device_attribute
*attr
, const char *buf
, size_t count
)
151 struct qeth_card
*card
= dev_get_drvdata(dev
);
158 mutex_lock(&card
->conf_mutex
);
159 if ((card
->state
!= CARD_STATE_DOWN
) &&
160 (card
->state
!= CARD_STATE_RECOVER
)) {
165 i
= simple_strtoul(buf
, &tmp
, 16);
166 if ((i
== 0) || (i
== 1))
167 card
->options
.fake_broadcast
= i
;
171 mutex_unlock(&card
->conf_mutex
);
172 return rc
? rc
: count
;
175 static DEVICE_ATTR(fake_broadcast
, 0644, qeth_l3_dev_fake_broadcast_show
,
176 qeth_l3_dev_fake_broadcast_store
);
178 static ssize_t
qeth_l3_dev_broadcast_mode_show(struct device
*dev
,
179 struct device_attribute
*attr
, char *buf
)
181 struct qeth_card
*card
= dev_get_drvdata(dev
);
186 if (!((card
->info
.link_type
== QETH_LINK_TYPE_HSTR
) ||
187 (card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
)))
188 return sprintf(buf
, "n/a\n");
190 return sprintf(buf
, "%s\n", (card
->options
.broadcast_mode
==
191 QETH_TR_BROADCAST_ALLRINGS
)?
192 "all rings":"local");
195 static ssize_t
qeth_l3_dev_broadcast_mode_store(struct device
*dev
,
196 struct device_attribute
*attr
, const char *buf
, size_t count
)
198 struct qeth_card
*card
= dev_get_drvdata(dev
);
205 mutex_lock(&card
->conf_mutex
);
206 if ((card
->state
!= CARD_STATE_DOWN
) &&
207 (card
->state
!= CARD_STATE_RECOVER
)) {
212 if (!((card
->info
.link_type
== QETH_LINK_TYPE_HSTR
) ||
213 (card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
))) {
218 tmp
= strsep((char **) &buf
, "\n");
220 if (!strcmp(tmp
, "local"))
221 card
->options
.broadcast_mode
= QETH_TR_BROADCAST_LOCAL
;
222 else if (!strcmp(tmp
, "all_rings"))
223 card
->options
.broadcast_mode
= QETH_TR_BROADCAST_ALLRINGS
;
227 mutex_unlock(&card
->conf_mutex
);
228 return rc
? rc
: count
;
231 static DEVICE_ATTR(broadcast_mode
, 0644, qeth_l3_dev_broadcast_mode_show
,
232 qeth_l3_dev_broadcast_mode_store
);
234 static ssize_t
qeth_l3_dev_canonical_macaddr_show(struct device
*dev
,
235 struct device_attribute
*attr
, char *buf
)
237 struct qeth_card
*card
= dev_get_drvdata(dev
);
242 if (!((card
->info
.link_type
== QETH_LINK_TYPE_HSTR
) ||
243 (card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
)))
244 return sprintf(buf
, "n/a\n");
246 return sprintf(buf
, "%i\n", (card
->options
.macaddr_mode
==
247 QETH_TR_MACADDR_CANONICAL
)? 1:0);
250 static ssize_t
qeth_l3_dev_canonical_macaddr_store(struct device
*dev
,
251 struct device_attribute
*attr
, const char *buf
, size_t count
)
253 struct qeth_card
*card
= dev_get_drvdata(dev
);
260 mutex_lock(&card
->conf_mutex
);
261 if ((card
->state
!= CARD_STATE_DOWN
) &&
262 (card
->state
!= CARD_STATE_RECOVER
)) {
267 if (!((card
->info
.link_type
== QETH_LINK_TYPE_HSTR
) ||
268 (card
->info
.link_type
== QETH_LINK_TYPE_LANE_TR
))) {
273 i
= simple_strtoul(buf
, &tmp
, 16);
274 if ((i
== 0) || (i
== 1))
275 card
->options
.macaddr_mode
= i
?
276 QETH_TR_MACADDR_CANONICAL
:
277 QETH_TR_MACADDR_NONCANONICAL
;
281 mutex_unlock(&card
->conf_mutex
);
282 return rc
? rc
: count
;
285 static DEVICE_ATTR(canonical_macaddr
, 0644, qeth_l3_dev_canonical_macaddr_show
,
286 qeth_l3_dev_canonical_macaddr_store
);
288 static ssize_t
qeth_l3_dev_sniffer_show(struct device
*dev
,
289 struct device_attribute
*attr
, char *buf
)
291 struct qeth_card
*card
= dev_get_drvdata(dev
);
296 return sprintf(buf
, "%i\n", card
->options
.sniffer
? 1 : 0);
299 static ssize_t
qeth_l3_dev_sniffer_store(struct device
*dev
,
300 struct device_attribute
*attr
, const char *buf
, size_t count
)
302 struct qeth_card
*card
= dev_get_drvdata(dev
);
309 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
311 if (card
->options
.cq
== QETH_CQ_ENABLED
)
314 mutex_lock(&card
->conf_mutex
);
315 if ((card
->state
!= CARD_STATE_DOWN
) &&
316 (card
->state
!= CARD_STATE_RECOVER
)) {
321 rc
= strict_strtoul(buf
, 16, &i
);
328 card
->options
.sniffer
= i
;
331 qdio_get_ssqd_desc(CARD_DDEV(card
), &card
->ssqd
);
332 if (card
->ssqd
.qdioac2
& QETH_SNIFF_AVAIL
) {
333 card
->options
.sniffer
= i
;
334 if (card
->qdio
.init_pool
.buf_count
!=
335 QETH_IN_BUF_COUNT_MAX
)
336 qeth_realloc_buffer_pool(card
,
337 QETH_IN_BUF_COUNT_MAX
);
345 mutex_unlock(&card
->conf_mutex
);
346 return rc
? rc
: count
;
349 static DEVICE_ATTR(sniffer
, 0644, qeth_l3_dev_sniffer_show
,
350 qeth_l3_dev_sniffer_store
);
353 static ssize_t
qeth_l3_dev_hsuid_show(struct device
*dev
,
354 struct device_attribute
*attr
, char *buf
)
356 struct qeth_card
*card
= dev_get_drvdata(dev
);
362 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
365 if (card
->state
== CARD_STATE_DOWN
)
368 memcpy(tmp_hsuid
, card
->options
.hsuid
, sizeof(tmp_hsuid
));
369 EBCASC(tmp_hsuid
, 8);
370 return sprintf(buf
, "%s\n", tmp_hsuid
);
373 static ssize_t
qeth_l3_dev_hsuid_store(struct device
*dev
,
374 struct device_attribute
*attr
, const char *buf
, size_t count
)
376 struct qeth_card
*card
= dev_get_drvdata(dev
);
377 struct qeth_ipaddr
*addr
;
384 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
386 if (card
->state
!= CARD_STATE_DOWN
&&
387 card
->state
!= CARD_STATE_RECOVER
)
389 if (card
->options
.sniffer
)
391 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
)
394 tmp
= strsep((char **)&buf
, "\n");
398 if (card
->options
.hsuid
[0]) {
399 /* delete old ip address */
400 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
402 addr
->u
.a6
.addr
.s6_addr32
[0] = 0xfe800000;
403 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
404 for (i
= 8; i
< 16; i
++)
405 addr
->u
.a6
.addr
.s6_addr
[i
] =
406 card
->options
.hsuid
[i
- 8];
407 addr
->u
.a6
.pfxlen
= 0;
408 addr
->type
= QETH_IP_TYPE_NORMAL
;
411 if (!qeth_l3_delete_ip(card
, addr
))
413 qeth_l3_set_ip_addr_list(card
);
416 if (strlen(tmp
) == 0) {
417 /* delete ip address only */
418 card
->options
.hsuid
[0] = '\0';
420 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
421 qeth_configure_cq(card
, QETH_CQ_DISABLED
);
425 if (qeth_configure_cq(card
, QETH_CQ_ENABLED
))
428 for (i
= 0; i
< 8; i
++)
429 card
->options
.hsuid
[i
] = ' ';
430 card
->options
.hsuid
[8] = '\0';
431 strncpy(card
->options
.hsuid
, tmp
, strlen(tmp
));
432 ASCEBC(card
->options
.hsuid
, 8);
434 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
436 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
438 addr
->u
.a6
.addr
.s6_addr32
[0] = 0xfe800000;
439 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
440 for (i
= 8; i
< 16; i
++)
441 addr
->u
.a6
.addr
.s6_addr
[i
] = card
->options
.hsuid
[i
- 8];
442 addr
->u
.a6
.pfxlen
= 0;
443 addr
->type
= QETH_IP_TYPE_NORMAL
;
446 if (!qeth_l3_add_ip(card
, addr
))
448 qeth_l3_set_ip_addr_list(card
);
453 static DEVICE_ATTR(hsuid
, 0644, qeth_l3_dev_hsuid_show
,
454 qeth_l3_dev_hsuid_store
);
457 static struct attribute
*qeth_l3_device_attrs
[] = {
458 &dev_attr_route4
.attr
,
459 &dev_attr_route6
.attr
,
460 &dev_attr_fake_broadcast
.attr
,
461 &dev_attr_broadcast_mode
.attr
,
462 &dev_attr_canonical_macaddr
.attr
,
463 &dev_attr_sniffer
.attr
,
464 &dev_attr_hsuid
.attr
,
468 static struct attribute_group qeth_l3_device_attr_group
= {
469 .attrs
= qeth_l3_device_attrs
,
472 static ssize_t
qeth_l3_dev_ipato_enable_show(struct device
*dev
,
473 struct device_attribute
*attr
, char *buf
)
475 struct qeth_card
*card
= dev_get_drvdata(dev
);
480 return sprintf(buf
, "%i\n", card
->ipato
.enabled
? 1:0);
483 static ssize_t
qeth_l3_dev_ipato_enable_store(struct device
*dev
,
484 struct device_attribute
*attr
, const char *buf
, size_t count
)
486 struct qeth_card
*card
= dev_get_drvdata(dev
);
487 struct qeth_ipaddr
*tmpipa
, *t
;
494 mutex_lock(&card
->conf_mutex
);
495 if ((card
->state
!= CARD_STATE_DOWN
) &&
496 (card
->state
!= CARD_STATE_RECOVER
)) {
501 tmp
= strsep((char **) &buf
, "\n");
502 if (!strcmp(tmp
, "toggle")) {
503 card
->ipato
.enabled
= (card
->ipato
.enabled
)? 0 : 1;
504 } else if (!strcmp(tmp
, "1")) {
505 card
->ipato
.enabled
= 1;
506 list_for_each_entry_safe(tmpipa
, t
, card
->ip_tbd_list
, entry
) {
507 if ((tmpipa
->type
== QETH_IP_TYPE_NORMAL
) &&
508 qeth_l3_is_addr_covered_by_ipato(card
, tmpipa
))
510 QETH_IPA_SETIP_TAKEOVER_FLAG
;
513 } else if (!strcmp(tmp
, "0")) {
514 card
->ipato
.enabled
= 0;
515 list_for_each_entry_safe(tmpipa
, t
, card
->ip_tbd_list
, entry
) {
516 if (tmpipa
->set_flags
&
517 QETH_IPA_SETIP_TAKEOVER_FLAG
)
519 ~QETH_IPA_SETIP_TAKEOVER_FLAG
;
524 mutex_unlock(&card
->conf_mutex
);
525 return rc
? rc
: count
;
528 static QETH_DEVICE_ATTR(ipato_enable
, enable
, 0644,
529 qeth_l3_dev_ipato_enable_show
,
530 qeth_l3_dev_ipato_enable_store
);
532 static ssize_t
qeth_l3_dev_ipato_invert4_show(struct device
*dev
,
533 struct device_attribute
*attr
, char *buf
)
535 struct qeth_card
*card
= dev_get_drvdata(dev
);
540 return sprintf(buf
, "%i\n", card
->ipato
.invert4
? 1:0);
543 static ssize_t
qeth_l3_dev_ipato_invert4_store(struct device
*dev
,
544 struct device_attribute
*attr
,
545 const char *buf
, size_t count
)
547 struct qeth_card
*card
= dev_get_drvdata(dev
);
554 mutex_lock(&card
->conf_mutex
);
555 tmp
= strsep((char **) &buf
, "\n");
556 if (!strcmp(tmp
, "toggle")) {
557 card
->ipato
.invert4
= (card
->ipato
.invert4
)? 0 : 1;
558 } else if (!strcmp(tmp
, "1")) {
559 card
->ipato
.invert4
= 1;
560 } else if (!strcmp(tmp
, "0")) {
561 card
->ipato
.invert4
= 0;
564 mutex_unlock(&card
->conf_mutex
);
565 return rc
? rc
: count
;
568 static QETH_DEVICE_ATTR(ipato_invert4
, invert4
, 0644,
569 qeth_l3_dev_ipato_invert4_show
,
570 qeth_l3_dev_ipato_invert4_store
);
572 static ssize_t
qeth_l3_dev_ipato_add_show(char *buf
, struct qeth_card
*card
,
573 enum qeth_prot_versions proto
)
575 struct qeth_ipato_entry
*ipatoe
;
578 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
581 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
582 /* add strlen for "/<mask>\n" */
583 entry_len
+= (proto
== QETH_PROT_IPV4
)? 5 : 6;
584 spin_lock_irqsave(&card
->ip_lock
, flags
);
585 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
586 if (ipatoe
->proto
!= proto
)
588 /* String must not be longer than PAGE_SIZE. So we check if
589 * string length gets near PAGE_SIZE. Then we can savely display
590 * the next IPv6 address (worst case, compared to IPv4) */
591 if ((PAGE_SIZE
- i
) <= entry_len
)
593 qeth_l3_ipaddr_to_string(proto
, ipatoe
->addr
, addr_str
);
594 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
,
595 "%s/%i\n", addr_str
, ipatoe
->mask_bits
);
597 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
598 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
603 static ssize_t
qeth_l3_dev_ipato_add4_show(struct device
*dev
,
604 struct device_attribute
*attr
, char *buf
)
606 struct qeth_card
*card
= dev_get_drvdata(dev
);
611 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV4
);
614 static int qeth_l3_parse_ipatoe(const char *buf
, enum qeth_prot_versions proto
,
615 u8
*addr
, int *mask_bits
)
617 const char *start
, *end
;
619 char buffer
[40] = {0, };
622 /* get address string */
623 end
= strchr(start
, '/');
624 if (!end
|| (end
- start
>= 40)) {
627 strncpy(buffer
, start
, end
- start
);
628 if (qeth_l3_string_to_ipaddr(buffer
, proto
, addr
)) {
632 *mask_bits
= simple_strtoul(start
, &tmp
, 10);
633 if (!strlen(start
) ||
635 (*mask_bits
> ((proto
== QETH_PROT_IPV4
) ? 32 : 128))) {
641 static ssize_t
qeth_l3_dev_ipato_add_store(const char *buf
, size_t count
,
642 struct qeth_card
*card
, enum qeth_prot_versions proto
)
644 struct qeth_ipato_entry
*ipatoe
;
649 mutex_lock(&card
->conf_mutex
);
650 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
654 ipatoe
= kzalloc(sizeof(struct qeth_ipato_entry
), GFP_KERNEL
);
659 ipatoe
->proto
= proto
;
660 memcpy(ipatoe
->addr
, addr
, (proto
== QETH_PROT_IPV4
)? 4:16);
661 ipatoe
->mask_bits
= mask_bits
;
663 rc
= qeth_l3_add_ipato_entry(card
, ipatoe
);
667 mutex_unlock(&card
->conf_mutex
);
668 return rc
? rc
: count
;
671 static ssize_t
qeth_l3_dev_ipato_add4_store(struct device
*dev
,
672 struct device_attribute
*attr
, const char *buf
, size_t count
)
674 struct qeth_card
*card
= dev_get_drvdata(dev
);
679 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
682 static QETH_DEVICE_ATTR(ipato_add4
, add4
, 0644,
683 qeth_l3_dev_ipato_add4_show
,
684 qeth_l3_dev_ipato_add4_store
);
686 static ssize_t
qeth_l3_dev_ipato_del_store(const char *buf
, size_t count
,
687 struct qeth_card
*card
, enum qeth_prot_versions proto
)
693 mutex_lock(&card
->conf_mutex
);
694 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
696 qeth_l3_del_ipato_entry(card
, proto
, addr
, mask_bits
);
697 mutex_unlock(&card
->conf_mutex
);
698 return rc
? rc
: count
;
701 static ssize_t
qeth_l3_dev_ipato_del4_store(struct device
*dev
,
702 struct device_attribute
*attr
, const char *buf
, size_t count
)
704 struct qeth_card
*card
= dev_get_drvdata(dev
);
709 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
712 static QETH_DEVICE_ATTR(ipato_del4
, del4
, 0200, NULL
,
713 qeth_l3_dev_ipato_del4_store
);
715 static ssize_t
qeth_l3_dev_ipato_invert6_show(struct device
*dev
,
716 struct device_attribute
*attr
, char *buf
)
718 struct qeth_card
*card
= dev_get_drvdata(dev
);
723 return sprintf(buf
, "%i\n", card
->ipato
.invert6
? 1:0);
726 static ssize_t
qeth_l3_dev_ipato_invert6_store(struct device
*dev
,
727 struct device_attribute
*attr
, const char *buf
, size_t count
)
729 struct qeth_card
*card
= dev_get_drvdata(dev
);
736 mutex_lock(&card
->conf_mutex
);
737 tmp
= strsep((char **) &buf
, "\n");
738 if (!strcmp(tmp
, "toggle")) {
739 card
->ipato
.invert6
= (card
->ipato
.invert6
)? 0 : 1;
740 } else if (!strcmp(tmp
, "1")) {
741 card
->ipato
.invert6
= 1;
742 } else if (!strcmp(tmp
, "0")) {
743 card
->ipato
.invert6
= 0;
746 mutex_unlock(&card
->conf_mutex
);
747 return rc
? rc
: count
;
750 static QETH_DEVICE_ATTR(ipato_invert6
, invert6
, 0644,
751 qeth_l3_dev_ipato_invert6_show
,
752 qeth_l3_dev_ipato_invert6_store
);
755 static ssize_t
qeth_l3_dev_ipato_add6_show(struct device
*dev
,
756 struct device_attribute
*attr
, char *buf
)
758 struct qeth_card
*card
= dev_get_drvdata(dev
);
763 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV6
);
766 static ssize_t
qeth_l3_dev_ipato_add6_store(struct device
*dev
,
767 struct device_attribute
*attr
, const char *buf
, size_t count
)
769 struct qeth_card
*card
= dev_get_drvdata(dev
);
774 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
777 static QETH_DEVICE_ATTR(ipato_add6
, add6
, 0644,
778 qeth_l3_dev_ipato_add6_show
,
779 qeth_l3_dev_ipato_add6_store
);
781 static ssize_t
qeth_l3_dev_ipato_del6_store(struct device
*dev
,
782 struct device_attribute
*attr
, const char *buf
, size_t count
)
784 struct qeth_card
*card
= dev_get_drvdata(dev
);
789 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
792 static QETH_DEVICE_ATTR(ipato_del6
, del6
, 0200, NULL
,
793 qeth_l3_dev_ipato_del6_store
);
795 static struct attribute
*qeth_ipato_device_attrs
[] = {
796 &dev_attr_ipato_enable
.attr
,
797 &dev_attr_ipato_invert4
.attr
,
798 &dev_attr_ipato_add4
.attr
,
799 &dev_attr_ipato_del4
.attr
,
800 &dev_attr_ipato_invert6
.attr
,
801 &dev_attr_ipato_add6
.attr
,
802 &dev_attr_ipato_del6
.attr
,
806 static struct attribute_group qeth_device_ipato_group
= {
807 .name
= "ipa_takeover",
808 .attrs
= qeth_ipato_device_attrs
,
811 static ssize_t
qeth_l3_dev_vipa_add_show(char *buf
, struct qeth_card
*card
,
812 enum qeth_prot_versions proto
)
814 struct qeth_ipaddr
*ipaddr
;
816 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
820 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
821 entry_len
+= 2; /* \n + terminator */
822 spin_lock_irqsave(&card
->ip_lock
, flags
);
823 list_for_each_entry(ipaddr
, &card
->ip_list
, entry
) {
824 if (ipaddr
->proto
!= proto
)
826 if (ipaddr
->type
!= QETH_IP_TYPE_VIPA
)
828 /* String must not be longer than PAGE_SIZE. So we check if
829 * string length gets near PAGE_SIZE. Then we can savely display
830 * the next IPv6 address (worst case, compared to IPv4) */
831 if ((PAGE_SIZE
- i
) <= entry_len
)
833 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
835 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
837 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
838 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
843 static ssize_t
qeth_l3_dev_vipa_add4_show(struct device
*dev
,
844 struct device_attribute
*attr
, char *buf
)
846 struct qeth_card
*card
= dev_get_drvdata(dev
);
851 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV4
);
854 static int qeth_l3_parse_vipae(const char *buf
, enum qeth_prot_versions proto
,
857 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
863 static ssize_t
qeth_l3_dev_vipa_add_store(const char *buf
, size_t count
,
864 struct qeth_card
*card
, enum qeth_prot_versions proto
)
869 mutex_lock(&card
->conf_mutex
);
870 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
872 rc
= qeth_l3_add_vipa(card
, proto
, addr
);
873 mutex_unlock(&card
->conf_mutex
);
874 return rc
? rc
: count
;
877 static ssize_t
qeth_l3_dev_vipa_add4_store(struct device
*dev
,
878 struct device_attribute
*attr
, const char *buf
, size_t count
)
880 struct qeth_card
*card
= dev_get_drvdata(dev
);
885 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
888 static QETH_DEVICE_ATTR(vipa_add4
, add4
, 0644,
889 qeth_l3_dev_vipa_add4_show
,
890 qeth_l3_dev_vipa_add4_store
);
892 static ssize_t
qeth_l3_dev_vipa_del_store(const char *buf
, size_t count
,
893 struct qeth_card
*card
, enum qeth_prot_versions proto
)
898 mutex_lock(&card
->conf_mutex
);
899 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
901 qeth_l3_del_vipa(card
, proto
, addr
);
902 mutex_unlock(&card
->conf_mutex
);
903 return rc
? rc
: count
;
906 static ssize_t
qeth_l3_dev_vipa_del4_store(struct device
*dev
,
907 struct device_attribute
*attr
, const char *buf
, size_t count
)
909 struct qeth_card
*card
= dev_get_drvdata(dev
);
914 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
917 static QETH_DEVICE_ATTR(vipa_del4
, del4
, 0200, NULL
,
918 qeth_l3_dev_vipa_del4_store
);
920 static ssize_t
qeth_l3_dev_vipa_add6_show(struct device
*dev
,
921 struct device_attribute
*attr
, char *buf
)
923 struct qeth_card
*card
= dev_get_drvdata(dev
);
928 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV6
);
931 static ssize_t
qeth_l3_dev_vipa_add6_store(struct device
*dev
,
932 struct device_attribute
*attr
, const char *buf
, size_t count
)
934 struct qeth_card
*card
= dev_get_drvdata(dev
);
939 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
942 static QETH_DEVICE_ATTR(vipa_add6
, add6
, 0644,
943 qeth_l3_dev_vipa_add6_show
,
944 qeth_l3_dev_vipa_add6_store
);
946 static ssize_t
qeth_l3_dev_vipa_del6_store(struct device
*dev
,
947 struct device_attribute
*attr
, const char *buf
, size_t count
)
949 struct qeth_card
*card
= dev_get_drvdata(dev
);
954 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
957 static QETH_DEVICE_ATTR(vipa_del6
, del6
, 0200, NULL
,
958 qeth_l3_dev_vipa_del6_store
);
960 static struct attribute
*qeth_vipa_device_attrs
[] = {
961 &dev_attr_vipa_add4
.attr
,
962 &dev_attr_vipa_del4
.attr
,
963 &dev_attr_vipa_add6
.attr
,
964 &dev_attr_vipa_del6
.attr
,
968 static struct attribute_group qeth_device_vipa_group
= {
970 .attrs
= qeth_vipa_device_attrs
,
973 static ssize_t
qeth_l3_dev_rxip_add_show(char *buf
, struct qeth_card
*card
,
974 enum qeth_prot_versions proto
)
976 struct qeth_ipaddr
*ipaddr
;
978 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
982 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
983 entry_len
+= 2; /* \n + terminator */
984 spin_lock_irqsave(&card
->ip_lock
, flags
);
985 list_for_each_entry(ipaddr
, &card
->ip_list
, entry
) {
986 if (ipaddr
->proto
!= proto
)
988 if (ipaddr
->type
!= QETH_IP_TYPE_RXIP
)
990 /* String must not be longer than PAGE_SIZE. So we check if
991 * string length gets near PAGE_SIZE. Then we can savely display
992 * the next IPv6 address (worst case, compared to IPv4) */
993 if ((PAGE_SIZE
- i
) <= entry_len
)
995 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
997 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
999 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
1000 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
1005 static ssize_t
qeth_l3_dev_rxip_add4_show(struct device
*dev
,
1006 struct device_attribute
*attr
, char *buf
)
1008 struct qeth_card
*card
= dev_get_drvdata(dev
);
1013 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV4
);
1016 static int qeth_l3_parse_rxipe(const char *buf
, enum qeth_prot_versions proto
,
1019 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
1025 static ssize_t
qeth_l3_dev_rxip_add_store(const char *buf
, size_t count
,
1026 struct qeth_card
*card
, enum qeth_prot_versions proto
)
1028 u8 addr
[16] = {0, };
1031 mutex_lock(&card
->conf_mutex
);
1032 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
1034 rc
= qeth_l3_add_rxip(card
, proto
, addr
);
1035 mutex_unlock(&card
->conf_mutex
);
1036 return rc
? rc
: count
;
1039 static ssize_t
qeth_l3_dev_rxip_add4_store(struct device
*dev
,
1040 struct device_attribute
*attr
, const char *buf
, size_t count
)
1042 struct qeth_card
*card
= dev_get_drvdata(dev
);
1047 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
1050 static QETH_DEVICE_ATTR(rxip_add4
, add4
, 0644,
1051 qeth_l3_dev_rxip_add4_show
,
1052 qeth_l3_dev_rxip_add4_store
);
1054 static ssize_t
qeth_l3_dev_rxip_del_store(const char *buf
, size_t count
,
1055 struct qeth_card
*card
, enum qeth_prot_versions proto
)
1060 mutex_lock(&card
->conf_mutex
);
1061 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
1063 qeth_l3_del_rxip(card
, proto
, addr
);
1064 mutex_unlock(&card
->conf_mutex
);
1065 return rc
? rc
: count
;
1068 static ssize_t
qeth_l3_dev_rxip_del4_store(struct device
*dev
,
1069 struct device_attribute
*attr
, const char *buf
, size_t count
)
1071 struct qeth_card
*card
= dev_get_drvdata(dev
);
1076 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
1079 static QETH_DEVICE_ATTR(rxip_del4
, del4
, 0200, NULL
,
1080 qeth_l3_dev_rxip_del4_store
);
1082 static ssize_t
qeth_l3_dev_rxip_add6_show(struct device
*dev
,
1083 struct device_attribute
*attr
, char *buf
)
1085 struct qeth_card
*card
= dev_get_drvdata(dev
);
1090 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV6
);
1093 static ssize_t
qeth_l3_dev_rxip_add6_store(struct device
*dev
,
1094 struct device_attribute
*attr
, const char *buf
, size_t count
)
1096 struct qeth_card
*card
= dev_get_drvdata(dev
);
1101 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
1104 static QETH_DEVICE_ATTR(rxip_add6
, add6
, 0644,
1105 qeth_l3_dev_rxip_add6_show
,
1106 qeth_l3_dev_rxip_add6_store
);
1108 static ssize_t
qeth_l3_dev_rxip_del6_store(struct device
*dev
,
1109 struct device_attribute
*attr
, const char *buf
, size_t count
)
1111 struct qeth_card
*card
= dev_get_drvdata(dev
);
1116 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
1119 static QETH_DEVICE_ATTR(rxip_del6
, del6
, 0200, NULL
,
1120 qeth_l3_dev_rxip_del6_store
);
1122 static struct attribute
*qeth_rxip_device_attrs
[] = {
1123 &dev_attr_rxip_add4
.attr
,
1124 &dev_attr_rxip_del4
.attr
,
1125 &dev_attr_rxip_add6
.attr
,
1126 &dev_attr_rxip_del6
.attr
,
1130 static struct attribute_group qeth_device_rxip_group
= {
1132 .attrs
= qeth_rxip_device_attrs
,
1135 int qeth_l3_create_device_attributes(struct device
*dev
)
1139 ret
= sysfs_create_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1143 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_ipato_group
);
1145 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1149 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_vipa_group
);
1151 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1152 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1156 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_rxip_group
);
1158 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1159 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1160 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1166 void qeth_l3_remove_device_attributes(struct device
*dev
)
1168 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1169 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1170 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1171 sysfs_remove_group(&dev
->kobj
, &qeth_device_rxip_group
);