2 * Copyright IBM Corp. 2007
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 #include <linux/slab.h>
10 #include <asm/ebcdic.h>
11 #include <linux/hashtable.h>
14 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
15 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
17 static ssize_t
qeth_l3_dev_route_show(struct qeth_card
*card
,
18 struct qeth_routing_info
*route
, char *buf
)
20 switch (route
->type
) {
22 return sprintf(buf
, "%s\n", "primary router");
23 case SECONDARY_ROUTER
:
24 return sprintf(buf
, "%s\n", "secondary router");
25 case MULTICAST_ROUTER
:
26 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
27 return sprintf(buf
, "%s\n", "multicast router+");
29 return sprintf(buf
, "%s\n", "multicast router");
30 case PRIMARY_CONNECTOR
:
31 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
32 return sprintf(buf
, "%s\n", "primary connector+");
34 return sprintf(buf
, "%s\n", "primary connector");
35 case SECONDARY_CONNECTOR
:
36 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
37 return sprintf(buf
, "%s\n", "secondary connector+");
39 return sprintf(buf
, "%s\n", "secondary connector");
41 return sprintf(buf
, "%s\n", "no");
45 static ssize_t
qeth_l3_dev_route4_show(struct device
*dev
,
46 struct device_attribute
*attr
, char *buf
)
48 struct qeth_card
*card
= dev_get_drvdata(dev
);
53 return qeth_l3_dev_route_show(card
, &card
->options
.route4
, buf
);
56 static ssize_t
qeth_l3_dev_route_store(struct qeth_card
*card
,
57 struct qeth_routing_info
*route
, enum qeth_prot_versions prot
,
58 const char *buf
, size_t count
)
60 enum qeth_routing_types old_route_type
= route
->type
;
63 mutex_lock(&card
->conf_mutex
);
64 if (sysfs_streq(buf
, "no_router")) {
65 route
->type
= NO_ROUTER
;
66 } else if (sysfs_streq(buf
, "primary_connector")) {
67 route
->type
= PRIMARY_CONNECTOR
;
68 } else if (sysfs_streq(buf
, "secondary_connector")) {
69 route
->type
= SECONDARY_CONNECTOR
;
70 } else if (sysfs_streq(buf
, "primary_router")) {
71 route
->type
= PRIMARY_ROUTER
;
72 } else if (sysfs_streq(buf
, "secondary_router")) {
73 route
->type
= SECONDARY_ROUTER
;
74 } else if (sysfs_streq(buf
, "multicast_router")) {
75 route
->type
= MULTICAST_ROUTER
;
80 if (qeth_card_hw_is_reachable(card
) &&
81 (old_route_type
!= route
->type
)) {
82 if (prot
== QETH_PROT_IPV4
)
83 rc
= qeth_l3_setrouting_v4(card
);
84 else if (prot
== QETH_PROT_IPV6
)
85 rc
= qeth_l3_setrouting_v6(card
);
89 route
->type
= old_route_type
;
90 mutex_unlock(&card
->conf_mutex
);
91 return rc
? rc
: count
;
94 static ssize_t
qeth_l3_dev_route4_store(struct device
*dev
,
95 struct device_attribute
*attr
, const char *buf
, size_t count
)
97 struct qeth_card
*card
= dev_get_drvdata(dev
);
102 return qeth_l3_dev_route_store(card
, &card
->options
.route4
,
103 QETH_PROT_IPV4
, buf
, count
);
106 static DEVICE_ATTR(route4
, 0644, qeth_l3_dev_route4_show
,
107 qeth_l3_dev_route4_store
);
109 static ssize_t
qeth_l3_dev_route6_show(struct device
*dev
,
110 struct device_attribute
*attr
, char *buf
)
112 struct qeth_card
*card
= dev_get_drvdata(dev
);
117 return qeth_l3_dev_route_show(card
, &card
->options
.route6
, buf
);
120 static ssize_t
qeth_l3_dev_route6_store(struct device
*dev
,
121 struct device_attribute
*attr
, const char *buf
, size_t count
)
123 struct qeth_card
*card
= dev_get_drvdata(dev
);
128 return qeth_l3_dev_route_store(card
, &card
->options
.route6
,
129 QETH_PROT_IPV6
, buf
, count
);
132 static DEVICE_ATTR(route6
, 0644, qeth_l3_dev_route6_show
,
133 qeth_l3_dev_route6_store
);
135 static ssize_t
qeth_l3_dev_fake_broadcast_show(struct device
*dev
,
136 struct device_attribute
*attr
, char *buf
)
138 struct qeth_card
*card
= dev_get_drvdata(dev
);
143 return sprintf(buf
, "%i\n", card
->options
.fake_broadcast
? 1:0);
146 static ssize_t
qeth_l3_dev_fake_broadcast_store(struct device
*dev
,
147 struct device_attribute
*attr
, const char *buf
, size_t count
)
149 struct qeth_card
*card
= dev_get_drvdata(dev
);
156 mutex_lock(&card
->conf_mutex
);
157 if ((card
->state
!= CARD_STATE_DOWN
) &&
158 (card
->state
!= CARD_STATE_RECOVER
)) {
163 i
= simple_strtoul(buf
, &tmp
, 16);
164 if ((i
== 0) || (i
== 1))
165 card
->options
.fake_broadcast
= i
;
169 mutex_unlock(&card
->conf_mutex
);
170 return rc
? rc
: count
;
173 static DEVICE_ATTR(fake_broadcast
, 0644, qeth_l3_dev_fake_broadcast_show
,
174 qeth_l3_dev_fake_broadcast_store
);
176 static ssize_t
qeth_l3_dev_sniffer_show(struct device
*dev
,
177 struct device_attribute
*attr
, char *buf
)
179 struct qeth_card
*card
= dev_get_drvdata(dev
);
184 return sprintf(buf
, "%i\n", card
->options
.sniffer
? 1 : 0);
187 static ssize_t
qeth_l3_dev_sniffer_store(struct device
*dev
,
188 struct device_attribute
*attr
, const char *buf
, size_t count
)
190 struct qeth_card
*card
= dev_get_drvdata(dev
);
197 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
199 if (card
->options
.cq
== QETH_CQ_ENABLED
)
202 mutex_lock(&card
->conf_mutex
);
203 if ((card
->state
!= CARD_STATE_DOWN
) &&
204 (card
->state
!= CARD_STATE_RECOVER
)) {
209 rc
= kstrtoul(buf
, 16, &i
);
216 card
->options
.sniffer
= i
;
219 qdio_get_ssqd_desc(CARD_DDEV(card
), &card
->ssqd
);
220 if (card
->ssqd
.qdioac2
& QETH_SNIFF_AVAIL
) {
221 card
->options
.sniffer
= i
;
222 if (card
->qdio
.init_pool
.buf_count
!=
223 QETH_IN_BUF_COUNT_MAX
)
224 qeth_realloc_buffer_pool(card
,
225 QETH_IN_BUF_COUNT_MAX
);
233 mutex_unlock(&card
->conf_mutex
);
234 return rc
? rc
: count
;
237 static DEVICE_ATTR(sniffer
, 0644, qeth_l3_dev_sniffer_show
,
238 qeth_l3_dev_sniffer_store
);
241 static ssize_t
qeth_l3_dev_hsuid_show(struct device
*dev
,
242 struct device_attribute
*attr
, char *buf
)
244 struct qeth_card
*card
= dev_get_drvdata(dev
);
250 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
253 if (card
->state
== CARD_STATE_DOWN
)
256 memcpy(tmp_hsuid
, card
->options
.hsuid
, sizeof(tmp_hsuid
));
257 EBCASC(tmp_hsuid
, 8);
258 return sprintf(buf
, "%s\n", tmp_hsuid
);
261 static ssize_t
qeth_l3_dev_hsuid_store(struct device
*dev
,
262 struct device_attribute
*attr
, const char *buf
, size_t count
)
264 struct qeth_card
*card
= dev_get_drvdata(dev
);
265 struct qeth_ipaddr
*addr
;
272 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
274 if (card
->state
!= CARD_STATE_DOWN
&&
275 card
->state
!= CARD_STATE_RECOVER
)
277 if (card
->options
.sniffer
)
279 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
)
282 tmp
= strsep((char **)&buf
, "\n");
286 if (card
->options
.hsuid
[0]) {
287 /* delete old ip address */
288 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
292 addr
->u
.a6
.addr
.s6_addr32
[0] = 0xfe800000;
293 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
294 for (i
= 8; i
< 16; i
++)
295 addr
->u
.a6
.addr
.s6_addr
[i
] =
296 card
->options
.hsuid
[i
- 8];
297 addr
->u
.a6
.pfxlen
= 0;
298 addr
->type
= QETH_IP_TYPE_NORMAL
;
300 spin_lock_bh(&card
->ip_lock
);
301 qeth_l3_delete_ip(card
, addr
);
302 spin_unlock_bh(&card
->ip_lock
);
306 if (strlen(tmp
) == 0) {
307 /* delete ip address only */
308 card
->options
.hsuid
[0] = '\0';
310 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
311 qeth_configure_cq(card
, QETH_CQ_DISABLED
);
315 if (qeth_configure_cq(card
, QETH_CQ_ENABLED
))
318 snprintf(card
->options
.hsuid
, sizeof(card
->options
.hsuid
),
320 ASCEBC(card
->options
.hsuid
, 8);
322 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
324 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
326 addr
->u
.a6
.addr
.s6_addr32
[0] = 0xfe800000;
327 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
328 for (i
= 8; i
< 16; i
++)
329 addr
->u
.a6
.addr
.s6_addr
[i
] = card
->options
.hsuid
[i
- 8];
330 addr
->u
.a6
.pfxlen
= 0;
331 addr
->type
= QETH_IP_TYPE_NORMAL
;
335 spin_lock_bh(&card
->ip_lock
);
336 qeth_l3_add_ip(card
, addr
);
337 spin_unlock_bh(&card
->ip_lock
);
343 static DEVICE_ATTR(hsuid
, 0644, qeth_l3_dev_hsuid_show
,
344 qeth_l3_dev_hsuid_store
);
347 static struct attribute
*qeth_l3_device_attrs
[] = {
348 &dev_attr_route4
.attr
,
349 &dev_attr_route6
.attr
,
350 &dev_attr_fake_broadcast
.attr
,
351 &dev_attr_sniffer
.attr
,
352 &dev_attr_hsuid
.attr
,
356 static struct attribute_group qeth_l3_device_attr_group
= {
357 .attrs
= qeth_l3_device_attrs
,
360 static ssize_t
qeth_l3_dev_ipato_enable_show(struct device
*dev
,
361 struct device_attribute
*attr
, char *buf
)
363 struct qeth_card
*card
= dev_get_drvdata(dev
);
368 return sprintf(buf
, "%i\n", card
->ipato
.enabled
? 1:0);
371 static ssize_t
qeth_l3_dev_ipato_enable_store(struct device
*dev
,
372 struct device_attribute
*attr
, const char *buf
, size_t count
)
374 struct qeth_card
*card
= dev_get_drvdata(dev
);
375 struct qeth_ipaddr
*addr
;
381 mutex_lock(&card
->conf_mutex
);
382 if ((card
->state
!= CARD_STATE_DOWN
) &&
383 (card
->state
!= CARD_STATE_RECOVER
)) {
388 if (sysfs_streq(buf
, "toggle")) {
389 card
->ipato
.enabled
= (card
->ipato
.enabled
)? 0 : 1;
390 } else if (sysfs_streq(buf
, "1")) {
391 card
->ipato
.enabled
= 1;
392 hash_for_each(card
->ip_htable
, i
, addr
, hnode
) {
393 if ((addr
->type
== QETH_IP_TYPE_NORMAL
) &&
394 qeth_l3_is_addr_covered_by_ipato(card
, addr
))
396 QETH_IPA_SETIP_TAKEOVER_FLAG
;
398 } else if (sysfs_streq(buf
, "0")) {
399 card
->ipato
.enabled
= 0;
400 hash_for_each(card
->ip_htable
, i
, addr
, hnode
) {
401 if (addr
->set_flags
&
402 QETH_IPA_SETIP_TAKEOVER_FLAG
)
404 ~QETH_IPA_SETIP_TAKEOVER_FLAG
;
409 mutex_unlock(&card
->conf_mutex
);
410 return rc
? rc
: count
;
413 static QETH_DEVICE_ATTR(ipato_enable
, enable
, 0644,
414 qeth_l3_dev_ipato_enable_show
,
415 qeth_l3_dev_ipato_enable_store
);
417 static ssize_t
qeth_l3_dev_ipato_invert4_show(struct device
*dev
,
418 struct device_attribute
*attr
, char *buf
)
420 struct qeth_card
*card
= dev_get_drvdata(dev
);
425 return sprintf(buf
, "%i\n", card
->ipato
.invert4
? 1:0);
428 static ssize_t
qeth_l3_dev_ipato_invert4_store(struct device
*dev
,
429 struct device_attribute
*attr
,
430 const char *buf
, size_t count
)
432 struct qeth_card
*card
= dev_get_drvdata(dev
);
438 mutex_lock(&card
->conf_mutex
);
439 if (sysfs_streq(buf
, "toggle"))
440 card
->ipato
.invert4
= (card
->ipato
.invert4
)? 0 : 1;
441 else if (sysfs_streq(buf
, "1"))
442 card
->ipato
.invert4
= 1;
443 else if (sysfs_streq(buf
, "0"))
444 card
->ipato
.invert4
= 0;
447 mutex_unlock(&card
->conf_mutex
);
448 return rc
? rc
: count
;
451 static QETH_DEVICE_ATTR(ipato_invert4
, invert4
, 0644,
452 qeth_l3_dev_ipato_invert4_show
,
453 qeth_l3_dev_ipato_invert4_store
);
455 static ssize_t
qeth_l3_dev_ipato_add_show(char *buf
, struct qeth_card
*card
,
456 enum qeth_prot_versions proto
)
458 struct qeth_ipato_entry
*ipatoe
;
460 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
463 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
464 /* add strlen for "/<mask>\n" */
465 entry_len
+= (proto
== QETH_PROT_IPV4
)? 5 : 6;
466 spin_lock_bh(&card
->ip_lock
);
467 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
468 if (ipatoe
->proto
!= proto
)
470 /* String must not be longer than PAGE_SIZE. So we check if
471 * string length gets near PAGE_SIZE. Then we can savely display
472 * the next IPv6 address (worst case, compared to IPv4) */
473 if ((PAGE_SIZE
- i
) <= entry_len
)
475 qeth_l3_ipaddr_to_string(proto
, ipatoe
->addr
, addr_str
);
476 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
,
477 "%s/%i\n", addr_str
, ipatoe
->mask_bits
);
479 spin_unlock_bh(&card
->ip_lock
);
480 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
485 static ssize_t
qeth_l3_dev_ipato_add4_show(struct device
*dev
,
486 struct device_attribute
*attr
, char *buf
)
488 struct qeth_card
*card
= dev_get_drvdata(dev
);
493 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV4
);
496 static int qeth_l3_parse_ipatoe(const char *buf
, enum qeth_prot_versions proto
,
497 u8
*addr
, int *mask_bits
)
499 const char *start
, *end
;
501 char buffer
[40] = {0, };
504 /* get address string */
505 end
= strchr(start
, '/');
506 if (!end
|| (end
- start
>= 40)) {
509 strncpy(buffer
, start
, end
- start
);
510 if (qeth_l3_string_to_ipaddr(buffer
, proto
, addr
)) {
514 *mask_bits
= simple_strtoul(start
, &tmp
, 10);
515 if (!strlen(start
) ||
517 (*mask_bits
> ((proto
== QETH_PROT_IPV4
) ? 32 : 128))) {
523 static ssize_t
qeth_l3_dev_ipato_add_store(const char *buf
, size_t count
,
524 struct qeth_card
*card
, enum qeth_prot_versions proto
)
526 struct qeth_ipato_entry
*ipatoe
;
531 mutex_lock(&card
->conf_mutex
);
532 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
536 ipatoe
= kzalloc(sizeof(struct qeth_ipato_entry
), GFP_KERNEL
);
541 ipatoe
->proto
= proto
;
542 memcpy(ipatoe
->addr
, addr
, (proto
== QETH_PROT_IPV4
)? 4:16);
543 ipatoe
->mask_bits
= mask_bits
;
545 rc
= qeth_l3_add_ipato_entry(card
, ipatoe
);
549 mutex_unlock(&card
->conf_mutex
);
550 return rc
? rc
: count
;
553 static ssize_t
qeth_l3_dev_ipato_add4_store(struct device
*dev
,
554 struct device_attribute
*attr
, const char *buf
, size_t count
)
556 struct qeth_card
*card
= dev_get_drvdata(dev
);
561 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
564 static QETH_DEVICE_ATTR(ipato_add4
, add4
, 0644,
565 qeth_l3_dev_ipato_add4_show
,
566 qeth_l3_dev_ipato_add4_store
);
568 static ssize_t
qeth_l3_dev_ipato_del_store(const char *buf
, size_t count
,
569 struct qeth_card
*card
, enum qeth_prot_versions proto
)
575 mutex_lock(&card
->conf_mutex
);
576 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
578 qeth_l3_del_ipato_entry(card
, proto
, addr
, mask_bits
);
579 mutex_unlock(&card
->conf_mutex
);
580 return rc
? rc
: count
;
583 static ssize_t
qeth_l3_dev_ipato_del4_store(struct device
*dev
,
584 struct device_attribute
*attr
, const char *buf
, size_t count
)
586 struct qeth_card
*card
= dev_get_drvdata(dev
);
591 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
594 static QETH_DEVICE_ATTR(ipato_del4
, del4
, 0200, NULL
,
595 qeth_l3_dev_ipato_del4_store
);
597 static ssize_t
qeth_l3_dev_ipato_invert6_show(struct device
*dev
,
598 struct device_attribute
*attr
, char *buf
)
600 struct qeth_card
*card
= dev_get_drvdata(dev
);
605 return sprintf(buf
, "%i\n", card
->ipato
.invert6
? 1:0);
608 static ssize_t
qeth_l3_dev_ipato_invert6_store(struct device
*dev
,
609 struct device_attribute
*attr
, const char *buf
, size_t count
)
611 struct qeth_card
*card
= dev_get_drvdata(dev
);
617 mutex_lock(&card
->conf_mutex
);
618 if (sysfs_streq(buf
, "toggle"))
619 card
->ipato
.invert6
= (card
->ipato
.invert6
)? 0 : 1;
620 else if (sysfs_streq(buf
, "1"))
621 card
->ipato
.invert6
= 1;
622 else if (sysfs_streq(buf
, "0"))
623 card
->ipato
.invert6
= 0;
626 mutex_unlock(&card
->conf_mutex
);
627 return rc
? rc
: count
;
630 static QETH_DEVICE_ATTR(ipato_invert6
, invert6
, 0644,
631 qeth_l3_dev_ipato_invert6_show
,
632 qeth_l3_dev_ipato_invert6_store
);
635 static ssize_t
qeth_l3_dev_ipato_add6_show(struct device
*dev
,
636 struct device_attribute
*attr
, char *buf
)
638 struct qeth_card
*card
= dev_get_drvdata(dev
);
643 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV6
);
646 static ssize_t
qeth_l3_dev_ipato_add6_store(struct device
*dev
,
647 struct device_attribute
*attr
, const char *buf
, size_t count
)
649 struct qeth_card
*card
= dev_get_drvdata(dev
);
654 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
657 static QETH_DEVICE_ATTR(ipato_add6
, add6
, 0644,
658 qeth_l3_dev_ipato_add6_show
,
659 qeth_l3_dev_ipato_add6_store
);
661 static ssize_t
qeth_l3_dev_ipato_del6_store(struct device
*dev
,
662 struct device_attribute
*attr
, const char *buf
, size_t count
)
664 struct qeth_card
*card
= dev_get_drvdata(dev
);
669 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
672 static QETH_DEVICE_ATTR(ipato_del6
, del6
, 0200, NULL
,
673 qeth_l3_dev_ipato_del6_store
);
675 static struct attribute
*qeth_ipato_device_attrs
[] = {
676 &dev_attr_ipato_enable
.attr
,
677 &dev_attr_ipato_invert4
.attr
,
678 &dev_attr_ipato_add4
.attr
,
679 &dev_attr_ipato_del4
.attr
,
680 &dev_attr_ipato_invert6
.attr
,
681 &dev_attr_ipato_add6
.attr
,
682 &dev_attr_ipato_del6
.attr
,
686 static struct attribute_group qeth_device_ipato_group
= {
687 .name
= "ipa_takeover",
688 .attrs
= qeth_ipato_device_attrs
,
691 static ssize_t
qeth_l3_dev_vipa_add_show(char *buf
, struct qeth_card
*card
,
692 enum qeth_prot_versions proto
)
694 struct qeth_ipaddr
*ipaddr
;
695 struct hlist_node
*tmp
;
697 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
700 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
701 entry_len
+= 2; /* \n + terminator */
702 spin_lock_bh(&card
->ip_lock
);
703 hash_for_each_safe(card
->ip_htable
, i
, tmp
, ipaddr
, hnode
) {
704 if (ipaddr
->proto
!= proto
)
706 if (ipaddr
->type
!= QETH_IP_TYPE_VIPA
)
708 /* String must not be longer than PAGE_SIZE. So we check if
709 * string length gets near PAGE_SIZE. Then we can savely display
710 * the next IPv6 address (worst case, compared to IPv4) */
711 if ((PAGE_SIZE
- i
) <= entry_len
)
713 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
715 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
717 spin_unlock_bh(&card
->ip_lock
);
718 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
723 static ssize_t
qeth_l3_dev_vipa_add4_show(struct device
*dev
,
724 struct device_attribute
*attr
, char *buf
)
726 struct qeth_card
*card
= dev_get_drvdata(dev
);
731 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV4
);
734 static int qeth_l3_parse_vipae(const char *buf
, enum qeth_prot_versions proto
,
737 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
743 static ssize_t
qeth_l3_dev_vipa_add_store(const char *buf
, size_t count
,
744 struct qeth_card
*card
, enum qeth_prot_versions proto
)
749 mutex_lock(&card
->conf_mutex
);
750 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
752 rc
= qeth_l3_add_vipa(card
, proto
, addr
);
753 mutex_unlock(&card
->conf_mutex
);
754 return rc
? rc
: count
;
757 static ssize_t
qeth_l3_dev_vipa_add4_store(struct device
*dev
,
758 struct device_attribute
*attr
, const char *buf
, size_t count
)
760 struct qeth_card
*card
= dev_get_drvdata(dev
);
765 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
768 static QETH_DEVICE_ATTR(vipa_add4
, add4
, 0644,
769 qeth_l3_dev_vipa_add4_show
,
770 qeth_l3_dev_vipa_add4_store
);
772 static ssize_t
qeth_l3_dev_vipa_del_store(const char *buf
, size_t count
,
773 struct qeth_card
*card
, enum qeth_prot_versions proto
)
778 mutex_lock(&card
->conf_mutex
);
779 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
781 qeth_l3_del_vipa(card
, proto
, addr
);
782 mutex_unlock(&card
->conf_mutex
);
783 return rc
? rc
: count
;
786 static ssize_t
qeth_l3_dev_vipa_del4_store(struct device
*dev
,
787 struct device_attribute
*attr
, const char *buf
, size_t count
)
789 struct qeth_card
*card
= dev_get_drvdata(dev
);
794 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
797 static QETH_DEVICE_ATTR(vipa_del4
, del4
, 0200, NULL
,
798 qeth_l3_dev_vipa_del4_store
);
800 static ssize_t
qeth_l3_dev_vipa_add6_show(struct device
*dev
,
801 struct device_attribute
*attr
, char *buf
)
803 struct qeth_card
*card
= dev_get_drvdata(dev
);
808 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV6
);
811 static ssize_t
qeth_l3_dev_vipa_add6_store(struct device
*dev
,
812 struct device_attribute
*attr
, const char *buf
, size_t count
)
814 struct qeth_card
*card
= dev_get_drvdata(dev
);
819 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
822 static QETH_DEVICE_ATTR(vipa_add6
, add6
, 0644,
823 qeth_l3_dev_vipa_add6_show
,
824 qeth_l3_dev_vipa_add6_store
);
826 static ssize_t
qeth_l3_dev_vipa_del6_store(struct device
*dev
,
827 struct device_attribute
*attr
, const char *buf
, size_t count
)
829 struct qeth_card
*card
= dev_get_drvdata(dev
);
834 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
837 static QETH_DEVICE_ATTR(vipa_del6
, del6
, 0200, NULL
,
838 qeth_l3_dev_vipa_del6_store
);
840 static struct attribute
*qeth_vipa_device_attrs
[] = {
841 &dev_attr_vipa_add4
.attr
,
842 &dev_attr_vipa_del4
.attr
,
843 &dev_attr_vipa_add6
.attr
,
844 &dev_attr_vipa_del6
.attr
,
848 static struct attribute_group qeth_device_vipa_group
= {
850 .attrs
= qeth_vipa_device_attrs
,
853 static ssize_t
qeth_l3_dev_rxip_add_show(char *buf
, struct qeth_card
*card
,
854 enum qeth_prot_versions proto
)
856 struct qeth_ipaddr
*ipaddr
;
857 struct hlist_node
*tmp
;
859 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
862 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
863 entry_len
+= 2; /* \n + terminator */
864 spin_lock_bh(&card
->ip_lock
);
865 hash_for_each_safe(card
->ip_htable
, i
, tmp
, ipaddr
, hnode
) {
866 if (ipaddr
->proto
!= proto
)
868 if (ipaddr
->type
!= QETH_IP_TYPE_RXIP
)
870 /* String must not be longer than PAGE_SIZE. So we check if
871 * string length gets near PAGE_SIZE. Then we can savely display
872 * the next IPv6 address (worst case, compared to IPv4) */
873 if ((PAGE_SIZE
- i
) <= entry_len
)
875 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
877 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
879 spin_unlock_bh(&card
->ip_lock
);
880 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\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
,
899 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
905 static ssize_t
qeth_l3_dev_rxip_add_store(const char *buf
, size_t count
,
906 struct qeth_card
*card
, enum qeth_prot_versions proto
)
911 mutex_lock(&card
->conf_mutex
);
912 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
914 rc
= qeth_l3_add_rxip(card
, proto
, addr
);
915 mutex_unlock(&card
->conf_mutex
);
916 return rc
? rc
: count
;
919 static ssize_t
qeth_l3_dev_rxip_add4_store(struct device
*dev
,
920 struct device_attribute
*attr
, const char *buf
, size_t count
)
922 struct qeth_card
*card
= dev_get_drvdata(dev
);
927 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
930 static QETH_DEVICE_ATTR(rxip_add4
, add4
, 0644,
931 qeth_l3_dev_rxip_add4_show
,
932 qeth_l3_dev_rxip_add4_store
);
934 static ssize_t
qeth_l3_dev_rxip_del_store(const char *buf
, size_t count
,
935 struct qeth_card
*card
, enum qeth_prot_versions proto
)
940 mutex_lock(&card
->conf_mutex
);
941 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
943 qeth_l3_del_rxip(card
, proto
, addr
);
944 mutex_unlock(&card
->conf_mutex
);
945 return rc
? rc
: count
;
948 static ssize_t
qeth_l3_dev_rxip_del4_store(struct device
*dev
,
949 struct device_attribute
*attr
, const char *buf
, size_t count
)
951 struct qeth_card
*card
= dev_get_drvdata(dev
);
956 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
959 static QETH_DEVICE_ATTR(rxip_del4
, del4
, 0200, NULL
,
960 qeth_l3_dev_rxip_del4_store
);
962 static ssize_t
qeth_l3_dev_rxip_add6_show(struct device
*dev
,
963 struct device_attribute
*attr
, char *buf
)
965 struct qeth_card
*card
= dev_get_drvdata(dev
);
970 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV6
);
973 static ssize_t
qeth_l3_dev_rxip_add6_store(struct device
*dev
,
974 struct device_attribute
*attr
, const char *buf
, size_t count
)
976 struct qeth_card
*card
= dev_get_drvdata(dev
);
981 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
984 static QETH_DEVICE_ATTR(rxip_add6
, add6
, 0644,
985 qeth_l3_dev_rxip_add6_show
,
986 qeth_l3_dev_rxip_add6_store
);
988 static ssize_t
qeth_l3_dev_rxip_del6_store(struct device
*dev
,
989 struct device_attribute
*attr
, const char *buf
, size_t count
)
991 struct qeth_card
*card
= dev_get_drvdata(dev
);
996 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
999 static QETH_DEVICE_ATTR(rxip_del6
, del6
, 0200, NULL
,
1000 qeth_l3_dev_rxip_del6_store
);
1002 static struct attribute
*qeth_rxip_device_attrs
[] = {
1003 &dev_attr_rxip_add4
.attr
,
1004 &dev_attr_rxip_del4
.attr
,
1005 &dev_attr_rxip_add6
.attr
,
1006 &dev_attr_rxip_del6
.attr
,
1010 static struct attribute_group qeth_device_rxip_group
= {
1012 .attrs
= qeth_rxip_device_attrs
,
1015 int qeth_l3_create_device_attributes(struct device
*dev
)
1019 ret
= sysfs_create_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1023 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_ipato_group
);
1025 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1029 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_vipa_group
);
1031 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1032 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1036 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_rxip_group
);
1038 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1039 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1040 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1046 void qeth_l3_remove_device_attributes(struct device
*dev
)
1048 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1049 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1050 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1051 sysfs_remove_group(&dev
->kobj
, &qeth_device_rxip_group
);