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>
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
)
312 mutex_lock(&card
->conf_mutex
);
313 if ((card
->state
!= CARD_STATE_DOWN
) &&
314 (card
->state
!= CARD_STATE_RECOVER
)) {
319 rc
= strict_strtoul(buf
, 16, &i
);
326 card
->options
.sniffer
= i
;
329 qdio_get_ssqd_desc(CARD_DDEV(card
), &card
->ssqd
);
330 if (card
->ssqd
.qdioac2
& QETH_SNIFF_AVAIL
) {
331 card
->options
.sniffer
= i
;
332 if (card
->qdio
.init_pool
.buf_count
!=
333 QETH_IN_BUF_COUNT_MAX
)
334 qeth_realloc_buffer_pool(card
,
335 QETH_IN_BUF_COUNT_MAX
);
339 default: /* fall through */
343 mutex_unlock(&card
->conf_mutex
);
344 return rc
? rc
: count
;
347 static DEVICE_ATTR(sniffer
, 0644, qeth_l3_dev_sniffer_show
,
348 qeth_l3_dev_sniffer_store
);
350 static struct attribute
*qeth_l3_device_attrs
[] = {
351 &dev_attr_route4
.attr
,
352 &dev_attr_route6
.attr
,
353 &dev_attr_fake_broadcast
.attr
,
354 &dev_attr_broadcast_mode
.attr
,
355 &dev_attr_canonical_macaddr
.attr
,
356 &dev_attr_sniffer
.attr
,
360 static struct attribute_group qeth_l3_device_attr_group
= {
361 .attrs
= qeth_l3_device_attrs
,
364 static ssize_t
qeth_l3_dev_ipato_enable_show(struct device
*dev
,
365 struct device_attribute
*attr
, char *buf
)
367 struct qeth_card
*card
= dev_get_drvdata(dev
);
372 return sprintf(buf
, "%i\n", card
->ipato
.enabled
? 1:0);
375 static ssize_t
qeth_l3_dev_ipato_enable_store(struct device
*dev
,
376 struct device_attribute
*attr
, const char *buf
, size_t count
)
378 struct qeth_card
*card
= dev_get_drvdata(dev
);
379 struct qeth_ipaddr
*tmpipa
, *t
;
386 mutex_lock(&card
->conf_mutex
);
387 if ((card
->state
!= CARD_STATE_DOWN
) &&
388 (card
->state
!= CARD_STATE_RECOVER
)) {
393 tmp
= strsep((char **) &buf
, "\n");
394 if (!strcmp(tmp
, "toggle")) {
395 card
->ipato
.enabled
= (card
->ipato
.enabled
)? 0 : 1;
396 } else if (!strcmp(tmp
, "1")) {
397 card
->ipato
.enabled
= 1;
398 list_for_each_entry_safe(tmpipa
, t
, card
->ip_tbd_list
, entry
) {
399 if ((tmpipa
->type
== QETH_IP_TYPE_NORMAL
) &&
400 qeth_l3_is_addr_covered_by_ipato(card
, tmpipa
))
402 QETH_IPA_SETIP_TAKEOVER_FLAG
;
405 } else if (!strcmp(tmp
, "0")) {
406 card
->ipato
.enabled
= 0;
407 list_for_each_entry_safe(tmpipa
, t
, card
->ip_tbd_list
, entry
) {
408 if (tmpipa
->set_flags
&
409 QETH_IPA_SETIP_TAKEOVER_FLAG
)
411 ~QETH_IPA_SETIP_TAKEOVER_FLAG
;
416 mutex_unlock(&card
->conf_mutex
);
417 return rc
? rc
: count
;
420 static QETH_DEVICE_ATTR(ipato_enable
, enable
, 0644,
421 qeth_l3_dev_ipato_enable_show
,
422 qeth_l3_dev_ipato_enable_store
);
424 static ssize_t
qeth_l3_dev_ipato_invert4_show(struct device
*dev
,
425 struct device_attribute
*attr
, char *buf
)
427 struct qeth_card
*card
= dev_get_drvdata(dev
);
432 return sprintf(buf
, "%i\n", card
->ipato
.invert4
? 1:0);
435 static ssize_t
qeth_l3_dev_ipato_invert4_store(struct device
*dev
,
436 struct device_attribute
*attr
,
437 const char *buf
, size_t count
)
439 struct qeth_card
*card
= dev_get_drvdata(dev
);
446 mutex_lock(&card
->conf_mutex
);
447 tmp
= strsep((char **) &buf
, "\n");
448 if (!strcmp(tmp
, "toggle")) {
449 card
->ipato
.invert4
= (card
->ipato
.invert4
)? 0 : 1;
450 } else if (!strcmp(tmp
, "1")) {
451 card
->ipato
.invert4
= 1;
452 } else if (!strcmp(tmp
, "0")) {
453 card
->ipato
.invert4
= 0;
456 mutex_unlock(&card
->conf_mutex
);
457 return rc
? rc
: count
;
460 static QETH_DEVICE_ATTR(ipato_invert4
, invert4
, 0644,
461 qeth_l3_dev_ipato_invert4_show
,
462 qeth_l3_dev_ipato_invert4_store
);
464 static ssize_t
qeth_l3_dev_ipato_add_show(char *buf
, struct qeth_card
*card
,
465 enum qeth_prot_versions proto
)
467 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_irqsave(&card
->ip_lock
, flags
);
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_irqrestore(&card
->ip_lock
, flags
);
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 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 tmp
= strsep((char **) &buf
, "\n");
630 if (!strcmp(tmp
, "toggle")) {
631 card
->ipato
.invert6
= (card
->ipato
.invert6
)? 0 : 1;
632 } else if (!strcmp(tmp
, "1")) {
633 card
->ipato
.invert6
= 1;
634 } else if (!strcmp(tmp
, "0")) {
635 card
->ipato
.invert6
= 0;
638 mutex_unlock(&card
->conf_mutex
);
639 return rc
? rc
: count
;
642 static QETH_DEVICE_ATTR(ipato_invert6
, invert6
, 0644,
643 qeth_l3_dev_ipato_invert6_show
,
644 qeth_l3_dev_ipato_invert6_store
);
647 static ssize_t
qeth_l3_dev_ipato_add6_show(struct device
*dev
,
648 struct device_attribute
*attr
, char *buf
)
650 struct qeth_card
*card
= dev_get_drvdata(dev
);
655 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV6
);
658 static ssize_t
qeth_l3_dev_ipato_add6_store(struct device
*dev
,
659 struct device_attribute
*attr
, const char *buf
, size_t count
)
661 struct qeth_card
*card
= dev_get_drvdata(dev
);
666 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
669 static QETH_DEVICE_ATTR(ipato_add6
, add6
, 0644,
670 qeth_l3_dev_ipato_add6_show
,
671 qeth_l3_dev_ipato_add6_store
);
673 static ssize_t
qeth_l3_dev_ipato_del6_store(struct device
*dev
,
674 struct device_attribute
*attr
, const char *buf
, size_t count
)
676 struct qeth_card
*card
= dev_get_drvdata(dev
);
681 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
684 static QETH_DEVICE_ATTR(ipato_del6
, del6
, 0200, NULL
,
685 qeth_l3_dev_ipato_del6_store
);
687 static struct attribute
*qeth_ipato_device_attrs
[] = {
688 &dev_attr_ipato_enable
.attr
,
689 &dev_attr_ipato_invert4
.attr
,
690 &dev_attr_ipato_add4
.attr
,
691 &dev_attr_ipato_del4
.attr
,
692 &dev_attr_ipato_invert6
.attr
,
693 &dev_attr_ipato_add6
.attr
,
694 &dev_attr_ipato_del6
.attr
,
698 static struct attribute_group qeth_device_ipato_group
= {
699 .name
= "ipa_takeover",
700 .attrs
= qeth_ipato_device_attrs
,
703 static ssize_t
qeth_l3_dev_vipa_add_show(char *buf
, struct qeth_card
*card
,
704 enum qeth_prot_versions proto
)
706 struct qeth_ipaddr
*ipaddr
;
708 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
712 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
713 entry_len
+= 2; /* \n + terminator */
714 spin_lock_irqsave(&card
->ip_lock
, flags
);
715 list_for_each_entry(ipaddr
, &card
->ip_list
, entry
) {
716 if (ipaddr
->proto
!= proto
)
718 if (ipaddr
->type
!= QETH_IP_TYPE_VIPA
)
720 /* String must not be longer than PAGE_SIZE. So we check if
721 * string length gets near PAGE_SIZE. Then we can savely display
722 * the next IPv6 address (worst case, compared to IPv4) */
723 if ((PAGE_SIZE
- i
) <= entry_len
)
725 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
727 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
729 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
730 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
735 static ssize_t
qeth_l3_dev_vipa_add4_show(struct device
*dev
,
736 struct device_attribute
*attr
, char *buf
)
738 struct qeth_card
*card
= dev_get_drvdata(dev
);
743 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV4
);
746 static int qeth_l3_parse_vipae(const char *buf
, enum qeth_prot_versions proto
,
749 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
755 static ssize_t
qeth_l3_dev_vipa_add_store(const char *buf
, size_t count
,
756 struct qeth_card
*card
, enum qeth_prot_versions proto
)
761 mutex_lock(&card
->conf_mutex
);
762 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
764 rc
= qeth_l3_add_vipa(card
, proto
, addr
);
765 mutex_unlock(&card
->conf_mutex
);
766 return rc
? rc
: count
;
769 static ssize_t
qeth_l3_dev_vipa_add4_store(struct device
*dev
,
770 struct device_attribute
*attr
, const char *buf
, size_t count
)
772 struct qeth_card
*card
= dev_get_drvdata(dev
);
777 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
780 static QETH_DEVICE_ATTR(vipa_add4
, add4
, 0644,
781 qeth_l3_dev_vipa_add4_show
,
782 qeth_l3_dev_vipa_add4_store
);
784 static ssize_t
qeth_l3_dev_vipa_del_store(const char *buf
, size_t count
,
785 struct qeth_card
*card
, enum qeth_prot_versions proto
)
790 mutex_lock(&card
->conf_mutex
);
791 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
793 qeth_l3_del_vipa(card
, proto
, addr
);
794 mutex_unlock(&card
->conf_mutex
);
795 return rc
? rc
: count
;
798 static ssize_t
qeth_l3_dev_vipa_del4_store(struct device
*dev
,
799 struct device_attribute
*attr
, const char *buf
, size_t count
)
801 struct qeth_card
*card
= dev_get_drvdata(dev
);
806 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
809 static QETH_DEVICE_ATTR(vipa_del4
, del4
, 0200, NULL
,
810 qeth_l3_dev_vipa_del4_store
);
812 static ssize_t
qeth_l3_dev_vipa_add6_show(struct device
*dev
,
813 struct device_attribute
*attr
, char *buf
)
815 struct qeth_card
*card
= dev_get_drvdata(dev
);
820 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV6
);
823 static ssize_t
qeth_l3_dev_vipa_add6_store(struct device
*dev
,
824 struct device_attribute
*attr
, const char *buf
, size_t count
)
826 struct qeth_card
*card
= dev_get_drvdata(dev
);
831 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
834 static QETH_DEVICE_ATTR(vipa_add6
, add6
, 0644,
835 qeth_l3_dev_vipa_add6_show
,
836 qeth_l3_dev_vipa_add6_store
);
838 static ssize_t
qeth_l3_dev_vipa_del6_store(struct device
*dev
,
839 struct device_attribute
*attr
, const char *buf
, size_t count
)
841 struct qeth_card
*card
= dev_get_drvdata(dev
);
846 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
849 static QETH_DEVICE_ATTR(vipa_del6
, del6
, 0200, NULL
,
850 qeth_l3_dev_vipa_del6_store
);
852 static struct attribute
*qeth_vipa_device_attrs
[] = {
853 &dev_attr_vipa_add4
.attr
,
854 &dev_attr_vipa_del4
.attr
,
855 &dev_attr_vipa_add6
.attr
,
856 &dev_attr_vipa_del6
.attr
,
860 static struct attribute_group qeth_device_vipa_group
= {
862 .attrs
= qeth_vipa_device_attrs
,
865 static ssize_t
qeth_l3_dev_rxip_add_show(char *buf
, struct qeth_card
*card
,
866 enum qeth_prot_versions proto
)
868 struct qeth_ipaddr
*ipaddr
;
870 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
874 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
875 entry_len
+= 2; /* \n + terminator */
876 spin_lock_irqsave(&card
->ip_lock
, flags
);
877 list_for_each_entry(ipaddr
, &card
->ip_list
, entry
) {
878 if (ipaddr
->proto
!= proto
)
880 if (ipaddr
->type
!= QETH_IP_TYPE_RXIP
)
882 /* String must not be longer than PAGE_SIZE. So we check if
883 * string length gets near PAGE_SIZE. Then we can savely display
884 * the next IPv6 address (worst case, compared to IPv4) */
885 if ((PAGE_SIZE
- i
) <= entry_len
)
887 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
889 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
891 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
892 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
897 static ssize_t
qeth_l3_dev_rxip_add4_show(struct device
*dev
,
898 struct device_attribute
*attr
, char *buf
)
900 struct qeth_card
*card
= dev_get_drvdata(dev
);
905 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV4
);
908 static int qeth_l3_parse_rxipe(const char *buf
, enum qeth_prot_versions proto
,
911 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
917 static ssize_t
qeth_l3_dev_rxip_add_store(const char *buf
, size_t count
,
918 struct qeth_card
*card
, enum qeth_prot_versions proto
)
923 mutex_lock(&card
->conf_mutex
);
924 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
926 rc
= qeth_l3_add_rxip(card
, proto
, addr
);
927 mutex_unlock(&card
->conf_mutex
);
928 return rc
? rc
: count
;
931 static ssize_t
qeth_l3_dev_rxip_add4_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_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
942 static QETH_DEVICE_ATTR(rxip_add4
, add4
, 0644,
943 qeth_l3_dev_rxip_add4_show
,
944 qeth_l3_dev_rxip_add4_store
);
946 static ssize_t
qeth_l3_dev_rxip_del_store(const char *buf
, size_t count
,
947 struct qeth_card
*card
, enum qeth_prot_versions proto
)
952 mutex_lock(&card
->conf_mutex
);
953 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
955 qeth_l3_del_rxip(card
, proto
, addr
);
956 mutex_unlock(&card
->conf_mutex
);
957 return rc
? rc
: count
;
960 static ssize_t
qeth_l3_dev_rxip_del4_store(struct device
*dev
,
961 struct device_attribute
*attr
, const char *buf
, size_t count
)
963 struct qeth_card
*card
= dev_get_drvdata(dev
);
968 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
971 static QETH_DEVICE_ATTR(rxip_del4
, del4
, 0200, NULL
,
972 qeth_l3_dev_rxip_del4_store
);
974 static ssize_t
qeth_l3_dev_rxip_add6_show(struct device
*dev
,
975 struct device_attribute
*attr
, char *buf
)
977 struct qeth_card
*card
= dev_get_drvdata(dev
);
982 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV6
);
985 static ssize_t
qeth_l3_dev_rxip_add6_store(struct device
*dev
,
986 struct device_attribute
*attr
, const char *buf
, size_t count
)
988 struct qeth_card
*card
= dev_get_drvdata(dev
);
993 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
996 static QETH_DEVICE_ATTR(rxip_add6
, add6
, 0644,
997 qeth_l3_dev_rxip_add6_show
,
998 qeth_l3_dev_rxip_add6_store
);
1000 static ssize_t
qeth_l3_dev_rxip_del6_store(struct device
*dev
,
1001 struct device_attribute
*attr
, const char *buf
, size_t count
)
1003 struct qeth_card
*card
= dev_get_drvdata(dev
);
1008 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
1011 static QETH_DEVICE_ATTR(rxip_del6
, del6
, 0200, NULL
,
1012 qeth_l3_dev_rxip_del6_store
);
1014 static struct attribute
*qeth_rxip_device_attrs
[] = {
1015 &dev_attr_rxip_add4
.attr
,
1016 &dev_attr_rxip_del4
.attr
,
1017 &dev_attr_rxip_add6
.attr
,
1018 &dev_attr_rxip_del6
.attr
,
1022 static struct attribute_group qeth_device_rxip_group
= {
1024 .attrs
= qeth_rxip_device_attrs
,
1027 int qeth_l3_create_device_attributes(struct device
*dev
)
1031 ret
= sysfs_create_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1035 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_ipato_group
);
1037 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1041 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_vipa_group
);
1043 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1044 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1048 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_rxip_group
);
1050 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1051 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1052 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1058 void qeth_l3_remove_device_attributes(struct device
*dev
)
1060 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1061 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1062 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1063 sysfs_remove_group(&dev
->kobj
, &qeth_device_rxip_group
);