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>
13 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
14 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
16 static ssize_t
qeth_l3_dev_route_show(struct qeth_card
*card
,
17 struct qeth_routing_info
*route
, char *buf
)
19 switch (route
->type
) {
21 return sprintf(buf
, "%s\n", "primary router");
22 case SECONDARY_ROUTER
:
23 return sprintf(buf
, "%s\n", "secondary router");
24 case MULTICAST_ROUTER
:
25 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
26 return sprintf(buf
, "%s\n", "multicast router+");
28 return sprintf(buf
, "%s\n", "multicast router");
29 case PRIMARY_CONNECTOR
:
30 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
31 return sprintf(buf
, "%s\n", "primary connector+");
33 return sprintf(buf
, "%s\n", "primary connector");
34 case SECONDARY_CONNECTOR
:
35 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
36 return sprintf(buf
, "%s\n", "secondary connector+");
38 return sprintf(buf
, "%s\n", "secondary connector");
40 return sprintf(buf
, "%s\n", "no");
44 static ssize_t
qeth_l3_dev_route4_show(struct device
*dev
,
45 struct device_attribute
*attr
, char *buf
)
47 struct qeth_card
*card
= dev_get_drvdata(dev
);
52 return qeth_l3_dev_route_show(card
, &card
->options
.route4
, buf
);
55 static ssize_t
qeth_l3_dev_route_store(struct qeth_card
*card
,
56 struct qeth_routing_info
*route
, enum qeth_prot_versions prot
,
57 const char *buf
, size_t count
)
59 enum qeth_routing_types old_route_type
= route
->type
;
62 mutex_lock(&card
->conf_mutex
);
63 if (sysfs_streq(buf
, "no_router")) {
64 route
->type
= NO_ROUTER
;
65 } else if (sysfs_streq(buf
, "primary_connector")) {
66 route
->type
= PRIMARY_CONNECTOR
;
67 } else if (sysfs_streq(buf
, "secondary_connector")) {
68 route
->type
= SECONDARY_CONNECTOR
;
69 } else if (sysfs_streq(buf
, "primary_router")) {
70 route
->type
= PRIMARY_ROUTER
;
71 } else if (sysfs_streq(buf
, "secondary_router")) {
72 route
->type
= SECONDARY_ROUTER
;
73 } else if (sysfs_streq(buf
, "multicast_router")) {
74 route
->type
= MULTICAST_ROUTER
;
79 if (qeth_card_hw_is_reachable(card
) &&
80 (old_route_type
!= route
->type
)) {
81 if (prot
== QETH_PROT_IPV4
)
82 rc
= qeth_l3_setrouting_v4(card
);
83 else if (prot
== QETH_PROT_IPV6
)
84 rc
= qeth_l3_setrouting_v6(card
);
88 route
->type
= old_route_type
;
89 mutex_unlock(&card
->conf_mutex
);
90 return rc
? rc
: count
;
93 static ssize_t
qeth_l3_dev_route4_store(struct device
*dev
,
94 struct device_attribute
*attr
, const char *buf
, size_t count
)
96 struct qeth_card
*card
= dev_get_drvdata(dev
);
101 return qeth_l3_dev_route_store(card
, &card
->options
.route4
,
102 QETH_PROT_IPV4
, buf
, count
);
105 static DEVICE_ATTR(route4
, 0644, qeth_l3_dev_route4_show
,
106 qeth_l3_dev_route4_store
);
108 static ssize_t
qeth_l3_dev_route6_show(struct device
*dev
,
109 struct device_attribute
*attr
, char *buf
)
111 struct qeth_card
*card
= dev_get_drvdata(dev
);
116 return qeth_l3_dev_route_show(card
, &card
->options
.route6
, buf
);
119 static ssize_t
qeth_l3_dev_route6_store(struct device
*dev
,
120 struct device_attribute
*attr
, const char *buf
, size_t count
)
122 struct qeth_card
*card
= dev_get_drvdata(dev
);
127 return qeth_l3_dev_route_store(card
, &card
->options
.route6
,
128 QETH_PROT_IPV6
, buf
, count
);
131 static DEVICE_ATTR(route6
, 0644, qeth_l3_dev_route6_show
,
132 qeth_l3_dev_route6_store
);
134 static ssize_t
qeth_l3_dev_fake_broadcast_show(struct device
*dev
,
135 struct device_attribute
*attr
, char *buf
)
137 struct qeth_card
*card
= dev_get_drvdata(dev
);
142 return sprintf(buf
, "%i\n", card
->options
.fake_broadcast
? 1:0);
145 static ssize_t
qeth_l3_dev_fake_broadcast_store(struct device
*dev
,
146 struct device_attribute
*attr
, const char *buf
, size_t count
)
148 struct qeth_card
*card
= dev_get_drvdata(dev
);
155 mutex_lock(&card
->conf_mutex
);
156 if ((card
->state
!= CARD_STATE_DOWN
) &&
157 (card
->state
!= CARD_STATE_RECOVER
)) {
162 i
= simple_strtoul(buf
, &tmp
, 16);
163 if ((i
== 0) || (i
== 1))
164 card
->options
.fake_broadcast
= i
;
168 mutex_unlock(&card
->conf_mutex
);
169 return rc
? rc
: count
;
172 static DEVICE_ATTR(fake_broadcast
, 0644, qeth_l3_dev_fake_broadcast_show
,
173 qeth_l3_dev_fake_broadcast_store
);
175 static ssize_t
qeth_l3_dev_sniffer_show(struct device
*dev
,
176 struct device_attribute
*attr
, char *buf
)
178 struct qeth_card
*card
= dev_get_drvdata(dev
);
183 return sprintf(buf
, "%i\n", card
->options
.sniffer
? 1 : 0);
186 static ssize_t
qeth_l3_dev_sniffer_store(struct device
*dev
,
187 struct device_attribute
*attr
, const char *buf
, size_t count
)
189 struct qeth_card
*card
= dev_get_drvdata(dev
);
196 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
198 if (card
->options
.cq
== QETH_CQ_ENABLED
)
201 mutex_lock(&card
->conf_mutex
);
202 if ((card
->state
!= CARD_STATE_DOWN
) &&
203 (card
->state
!= CARD_STATE_RECOVER
)) {
208 rc
= kstrtoul(buf
, 16, &i
);
215 card
->options
.sniffer
= i
;
218 qdio_get_ssqd_desc(CARD_DDEV(card
), &card
->ssqd
);
219 if (card
->ssqd
.qdioac2
& QETH_SNIFF_AVAIL
) {
220 card
->options
.sniffer
= i
;
221 if (card
->qdio
.init_pool
.buf_count
!=
222 QETH_IN_BUF_COUNT_MAX
)
223 qeth_realloc_buffer_pool(card
,
224 QETH_IN_BUF_COUNT_MAX
);
232 mutex_unlock(&card
->conf_mutex
);
233 return rc
? rc
: count
;
236 static DEVICE_ATTR(sniffer
, 0644, qeth_l3_dev_sniffer_show
,
237 qeth_l3_dev_sniffer_store
);
240 static ssize_t
qeth_l3_dev_hsuid_show(struct device
*dev
,
241 struct device_attribute
*attr
, char *buf
)
243 struct qeth_card
*card
= dev_get_drvdata(dev
);
249 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
252 if (card
->state
== CARD_STATE_DOWN
)
255 memcpy(tmp_hsuid
, card
->options
.hsuid
, sizeof(tmp_hsuid
));
256 EBCASC(tmp_hsuid
, 8);
257 return sprintf(buf
, "%s\n", tmp_hsuid
);
260 static ssize_t
qeth_l3_dev_hsuid_store(struct device
*dev
,
261 struct device_attribute
*attr
, const char *buf
, size_t count
)
263 struct qeth_card
*card
= dev_get_drvdata(dev
);
264 struct qeth_ipaddr
*addr
;
271 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
273 if (card
->state
!= CARD_STATE_DOWN
&&
274 card
->state
!= CARD_STATE_RECOVER
)
276 if (card
->options
.sniffer
)
278 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
)
281 tmp
= strsep((char **)&buf
, "\n");
285 if (card
->options
.hsuid
[0]) {
286 /* delete old ip address */
287 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
289 addr
->u
.a6
.addr
.s6_addr32
[0] = 0xfe800000;
290 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
291 for (i
= 8; i
< 16; i
++)
292 addr
->u
.a6
.addr
.s6_addr
[i
] =
293 card
->options
.hsuid
[i
- 8];
294 addr
->u
.a6
.pfxlen
= 0;
295 addr
->type
= QETH_IP_TYPE_NORMAL
;
298 if (!qeth_l3_delete_ip(card
, addr
))
300 qeth_l3_set_ip_addr_list(card
);
303 if (strlen(tmp
) == 0) {
304 /* delete ip address only */
305 card
->options
.hsuid
[0] = '\0';
307 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
308 qeth_configure_cq(card
, QETH_CQ_DISABLED
);
312 if (qeth_configure_cq(card
, QETH_CQ_ENABLED
))
315 snprintf(card
->options
.hsuid
, sizeof(card
->options
.hsuid
),
317 ASCEBC(card
->options
.hsuid
, 8);
319 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
321 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
323 addr
->u
.a6
.addr
.s6_addr32
[0] = 0xfe800000;
324 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
325 for (i
= 8; i
< 16; i
++)
326 addr
->u
.a6
.addr
.s6_addr
[i
] = card
->options
.hsuid
[i
- 8];
327 addr
->u
.a6
.pfxlen
= 0;
328 addr
->type
= QETH_IP_TYPE_NORMAL
;
331 if (!qeth_l3_add_ip(card
, addr
))
333 qeth_l3_set_ip_addr_list(card
);
338 static DEVICE_ATTR(hsuid
, 0644, qeth_l3_dev_hsuid_show
,
339 qeth_l3_dev_hsuid_store
);
342 static struct attribute
*qeth_l3_device_attrs
[] = {
343 &dev_attr_route4
.attr
,
344 &dev_attr_route6
.attr
,
345 &dev_attr_fake_broadcast
.attr
,
346 &dev_attr_sniffer
.attr
,
347 &dev_attr_hsuid
.attr
,
351 static struct attribute_group qeth_l3_device_attr_group
= {
352 .attrs
= qeth_l3_device_attrs
,
355 static ssize_t
qeth_l3_dev_ipato_enable_show(struct device
*dev
,
356 struct device_attribute
*attr
, char *buf
)
358 struct qeth_card
*card
= dev_get_drvdata(dev
);
363 return sprintf(buf
, "%i\n", card
->ipato
.enabled
? 1:0);
366 static ssize_t
qeth_l3_dev_ipato_enable_store(struct device
*dev
,
367 struct device_attribute
*attr
, const char *buf
, size_t count
)
369 struct qeth_card
*card
= dev_get_drvdata(dev
);
370 struct qeth_ipaddr
*tmpipa
, *t
;
376 mutex_lock(&card
->conf_mutex
);
377 if ((card
->state
!= CARD_STATE_DOWN
) &&
378 (card
->state
!= CARD_STATE_RECOVER
)) {
383 if (sysfs_streq(buf
, "toggle")) {
384 card
->ipato
.enabled
= (card
->ipato
.enabled
)? 0 : 1;
385 } else if (sysfs_streq(buf
, "1")) {
386 card
->ipato
.enabled
= 1;
387 list_for_each_entry_safe(tmpipa
, t
, card
->ip_tbd_list
, entry
) {
388 if ((tmpipa
->type
== QETH_IP_TYPE_NORMAL
) &&
389 qeth_l3_is_addr_covered_by_ipato(card
, tmpipa
))
391 QETH_IPA_SETIP_TAKEOVER_FLAG
;
394 } else if (sysfs_streq(buf
, "0")) {
395 card
->ipato
.enabled
= 0;
396 list_for_each_entry_safe(tmpipa
, t
, card
->ip_tbd_list
, entry
) {
397 if (tmpipa
->set_flags
&
398 QETH_IPA_SETIP_TAKEOVER_FLAG
)
400 ~QETH_IPA_SETIP_TAKEOVER_FLAG
;
405 mutex_unlock(&card
->conf_mutex
);
406 return rc
? rc
: count
;
409 static QETH_DEVICE_ATTR(ipato_enable
, enable
, 0644,
410 qeth_l3_dev_ipato_enable_show
,
411 qeth_l3_dev_ipato_enable_store
);
413 static ssize_t
qeth_l3_dev_ipato_invert4_show(struct device
*dev
,
414 struct device_attribute
*attr
, char *buf
)
416 struct qeth_card
*card
= dev_get_drvdata(dev
);
421 return sprintf(buf
, "%i\n", card
->ipato
.invert4
? 1:0);
424 static ssize_t
qeth_l3_dev_ipato_invert4_store(struct device
*dev
,
425 struct device_attribute
*attr
,
426 const char *buf
, size_t count
)
428 struct qeth_card
*card
= dev_get_drvdata(dev
);
434 mutex_lock(&card
->conf_mutex
);
435 if (sysfs_streq(buf
, "toggle"))
436 card
->ipato
.invert4
= (card
->ipato
.invert4
)? 0 : 1;
437 else if (sysfs_streq(buf
, "1"))
438 card
->ipato
.invert4
= 1;
439 else if (sysfs_streq(buf
, "0"))
440 card
->ipato
.invert4
= 0;
443 mutex_unlock(&card
->conf_mutex
);
444 return rc
? rc
: count
;
447 static QETH_DEVICE_ATTR(ipato_invert4
, invert4
, 0644,
448 qeth_l3_dev_ipato_invert4_show
,
449 qeth_l3_dev_ipato_invert4_store
);
451 static ssize_t
qeth_l3_dev_ipato_add_show(char *buf
, struct qeth_card
*card
,
452 enum qeth_prot_versions proto
)
454 struct qeth_ipato_entry
*ipatoe
;
457 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
460 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
461 /* add strlen for "/<mask>\n" */
462 entry_len
+= (proto
== QETH_PROT_IPV4
)? 5 : 6;
463 spin_lock_irqsave(&card
->ip_lock
, flags
);
464 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
465 if (ipatoe
->proto
!= proto
)
467 /* String must not be longer than PAGE_SIZE. So we check if
468 * string length gets near PAGE_SIZE. Then we can savely display
469 * the next IPv6 address (worst case, compared to IPv4) */
470 if ((PAGE_SIZE
- i
) <= entry_len
)
472 qeth_l3_ipaddr_to_string(proto
, ipatoe
->addr
, addr_str
);
473 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
,
474 "%s/%i\n", addr_str
, ipatoe
->mask_bits
);
476 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
477 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
482 static ssize_t
qeth_l3_dev_ipato_add4_show(struct device
*dev
,
483 struct device_attribute
*attr
, char *buf
)
485 struct qeth_card
*card
= dev_get_drvdata(dev
);
490 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV4
);
493 static int qeth_l3_parse_ipatoe(const char *buf
, enum qeth_prot_versions proto
,
494 u8
*addr
, int *mask_bits
)
496 const char *start
, *end
;
498 char buffer
[40] = {0, };
501 /* get address string */
502 end
= strchr(start
, '/');
503 if (!end
|| (end
- start
>= 40)) {
506 strncpy(buffer
, start
, end
- start
);
507 if (qeth_l3_string_to_ipaddr(buffer
, proto
, addr
)) {
511 *mask_bits
= simple_strtoul(start
, &tmp
, 10);
512 if (!strlen(start
) ||
514 (*mask_bits
> ((proto
== QETH_PROT_IPV4
) ? 32 : 128))) {
520 static ssize_t
qeth_l3_dev_ipato_add_store(const char *buf
, size_t count
,
521 struct qeth_card
*card
, enum qeth_prot_versions proto
)
523 struct qeth_ipato_entry
*ipatoe
;
528 mutex_lock(&card
->conf_mutex
);
529 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
533 ipatoe
= kzalloc(sizeof(struct qeth_ipato_entry
), GFP_KERNEL
);
538 ipatoe
->proto
= proto
;
539 memcpy(ipatoe
->addr
, addr
, (proto
== QETH_PROT_IPV4
)? 4:16);
540 ipatoe
->mask_bits
= mask_bits
;
542 rc
= qeth_l3_add_ipato_entry(card
, ipatoe
);
546 mutex_unlock(&card
->conf_mutex
);
547 return rc
? rc
: count
;
550 static ssize_t
qeth_l3_dev_ipato_add4_store(struct device
*dev
,
551 struct device_attribute
*attr
, const char *buf
, size_t count
)
553 struct qeth_card
*card
= dev_get_drvdata(dev
);
558 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
561 static QETH_DEVICE_ATTR(ipato_add4
, add4
, 0644,
562 qeth_l3_dev_ipato_add4_show
,
563 qeth_l3_dev_ipato_add4_store
);
565 static ssize_t
qeth_l3_dev_ipato_del_store(const char *buf
, size_t count
,
566 struct qeth_card
*card
, enum qeth_prot_versions proto
)
572 mutex_lock(&card
->conf_mutex
);
573 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
575 qeth_l3_del_ipato_entry(card
, proto
, addr
, mask_bits
);
576 mutex_unlock(&card
->conf_mutex
);
577 return rc
? rc
: count
;
580 static ssize_t
qeth_l3_dev_ipato_del4_store(struct device
*dev
,
581 struct device_attribute
*attr
, const char *buf
, size_t count
)
583 struct qeth_card
*card
= dev_get_drvdata(dev
);
588 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
591 static QETH_DEVICE_ATTR(ipato_del4
, del4
, 0200, NULL
,
592 qeth_l3_dev_ipato_del4_store
);
594 static ssize_t
qeth_l3_dev_ipato_invert6_show(struct device
*dev
,
595 struct device_attribute
*attr
, char *buf
)
597 struct qeth_card
*card
= dev_get_drvdata(dev
);
602 return sprintf(buf
, "%i\n", card
->ipato
.invert6
? 1:0);
605 static ssize_t
qeth_l3_dev_ipato_invert6_store(struct device
*dev
,
606 struct device_attribute
*attr
, const char *buf
, size_t count
)
608 struct qeth_card
*card
= dev_get_drvdata(dev
);
614 mutex_lock(&card
->conf_mutex
);
615 if (sysfs_streq(buf
, "toggle"))
616 card
->ipato
.invert6
= (card
->ipato
.invert6
)? 0 : 1;
617 else if (sysfs_streq(buf
, "1"))
618 card
->ipato
.invert6
= 1;
619 else if (sysfs_streq(buf
, "0"))
620 card
->ipato
.invert6
= 0;
623 mutex_unlock(&card
->conf_mutex
);
624 return rc
? rc
: count
;
627 static QETH_DEVICE_ATTR(ipato_invert6
, invert6
, 0644,
628 qeth_l3_dev_ipato_invert6_show
,
629 qeth_l3_dev_ipato_invert6_store
);
632 static ssize_t
qeth_l3_dev_ipato_add6_show(struct device
*dev
,
633 struct device_attribute
*attr
, char *buf
)
635 struct qeth_card
*card
= dev_get_drvdata(dev
);
640 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV6
);
643 static ssize_t
qeth_l3_dev_ipato_add6_store(struct device
*dev
,
644 struct device_attribute
*attr
, const char *buf
, size_t count
)
646 struct qeth_card
*card
= dev_get_drvdata(dev
);
651 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
654 static QETH_DEVICE_ATTR(ipato_add6
, add6
, 0644,
655 qeth_l3_dev_ipato_add6_show
,
656 qeth_l3_dev_ipato_add6_store
);
658 static ssize_t
qeth_l3_dev_ipato_del6_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_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
669 static QETH_DEVICE_ATTR(ipato_del6
, del6
, 0200, NULL
,
670 qeth_l3_dev_ipato_del6_store
);
672 static struct attribute
*qeth_ipato_device_attrs
[] = {
673 &dev_attr_ipato_enable
.attr
,
674 &dev_attr_ipato_invert4
.attr
,
675 &dev_attr_ipato_add4
.attr
,
676 &dev_attr_ipato_del4
.attr
,
677 &dev_attr_ipato_invert6
.attr
,
678 &dev_attr_ipato_add6
.attr
,
679 &dev_attr_ipato_del6
.attr
,
683 static struct attribute_group qeth_device_ipato_group
= {
684 .name
= "ipa_takeover",
685 .attrs
= qeth_ipato_device_attrs
,
688 static ssize_t
qeth_l3_dev_vipa_add_show(char *buf
, struct qeth_card
*card
,
689 enum qeth_prot_versions proto
)
691 struct qeth_ipaddr
*ipaddr
;
693 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
697 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
698 entry_len
+= 2; /* \n + terminator */
699 spin_lock_irqsave(&card
->ip_lock
, flags
);
700 list_for_each_entry(ipaddr
, &card
->ip_list
, entry
) {
701 if (ipaddr
->proto
!= proto
)
703 if (ipaddr
->type
!= QETH_IP_TYPE_VIPA
)
705 /* String must not be longer than PAGE_SIZE. So we check if
706 * string length gets near PAGE_SIZE. Then we can savely display
707 * the next IPv6 address (worst case, compared to IPv4) */
708 if ((PAGE_SIZE
- i
) <= entry_len
)
710 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
712 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
714 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
715 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
720 static ssize_t
qeth_l3_dev_vipa_add4_show(struct device
*dev
,
721 struct device_attribute
*attr
, char *buf
)
723 struct qeth_card
*card
= dev_get_drvdata(dev
);
728 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV4
);
731 static int qeth_l3_parse_vipae(const char *buf
, enum qeth_prot_versions proto
,
734 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
740 static ssize_t
qeth_l3_dev_vipa_add_store(const char *buf
, size_t count
,
741 struct qeth_card
*card
, enum qeth_prot_versions proto
)
746 mutex_lock(&card
->conf_mutex
);
747 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
749 rc
= qeth_l3_add_vipa(card
, proto
, addr
);
750 mutex_unlock(&card
->conf_mutex
);
751 return rc
? rc
: count
;
754 static ssize_t
qeth_l3_dev_vipa_add4_store(struct device
*dev
,
755 struct device_attribute
*attr
, const char *buf
, size_t count
)
757 struct qeth_card
*card
= dev_get_drvdata(dev
);
762 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
765 static QETH_DEVICE_ATTR(vipa_add4
, add4
, 0644,
766 qeth_l3_dev_vipa_add4_show
,
767 qeth_l3_dev_vipa_add4_store
);
769 static ssize_t
qeth_l3_dev_vipa_del_store(const char *buf
, size_t count
,
770 struct qeth_card
*card
, enum qeth_prot_versions proto
)
775 mutex_lock(&card
->conf_mutex
);
776 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
778 qeth_l3_del_vipa(card
, proto
, addr
);
779 mutex_unlock(&card
->conf_mutex
);
780 return rc
? rc
: count
;
783 static ssize_t
qeth_l3_dev_vipa_del4_store(struct device
*dev
,
784 struct device_attribute
*attr
, const char *buf
, size_t count
)
786 struct qeth_card
*card
= dev_get_drvdata(dev
);
791 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
794 static QETH_DEVICE_ATTR(vipa_del4
, del4
, 0200, NULL
,
795 qeth_l3_dev_vipa_del4_store
);
797 static ssize_t
qeth_l3_dev_vipa_add6_show(struct device
*dev
,
798 struct device_attribute
*attr
, char *buf
)
800 struct qeth_card
*card
= dev_get_drvdata(dev
);
805 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV6
);
808 static ssize_t
qeth_l3_dev_vipa_add6_store(struct device
*dev
,
809 struct device_attribute
*attr
, const char *buf
, size_t count
)
811 struct qeth_card
*card
= dev_get_drvdata(dev
);
816 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
819 static QETH_DEVICE_ATTR(vipa_add6
, add6
, 0644,
820 qeth_l3_dev_vipa_add6_show
,
821 qeth_l3_dev_vipa_add6_store
);
823 static ssize_t
qeth_l3_dev_vipa_del6_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_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
834 static QETH_DEVICE_ATTR(vipa_del6
, del6
, 0200, NULL
,
835 qeth_l3_dev_vipa_del6_store
);
837 static struct attribute
*qeth_vipa_device_attrs
[] = {
838 &dev_attr_vipa_add4
.attr
,
839 &dev_attr_vipa_del4
.attr
,
840 &dev_attr_vipa_add6
.attr
,
841 &dev_attr_vipa_del6
.attr
,
845 static struct attribute_group qeth_device_vipa_group
= {
847 .attrs
= qeth_vipa_device_attrs
,
850 static ssize_t
qeth_l3_dev_rxip_add_show(char *buf
, struct qeth_card
*card
,
851 enum qeth_prot_versions proto
)
853 struct qeth_ipaddr
*ipaddr
;
855 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
859 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
860 entry_len
+= 2; /* \n + terminator */
861 spin_lock_irqsave(&card
->ip_lock
, flags
);
862 list_for_each_entry(ipaddr
, &card
->ip_list
, entry
) {
863 if (ipaddr
->proto
!= proto
)
865 if (ipaddr
->type
!= QETH_IP_TYPE_RXIP
)
867 /* String must not be longer than PAGE_SIZE. So we check if
868 * string length gets near PAGE_SIZE. Then we can savely display
869 * the next IPv6 address (worst case, compared to IPv4) */
870 if ((PAGE_SIZE
- i
) <= entry_len
)
872 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
874 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
876 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
877 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
882 static ssize_t
qeth_l3_dev_rxip_add4_show(struct device
*dev
,
883 struct device_attribute
*attr
, char *buf
)
885 struct qeth_card
*card
= dev_get_drvdata(dev
);
890 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV4
);
893 static int qeth_l3_parse_rxipe(const char *buf
, enum qeth_prot_versions proto
,
896 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
902 static ssize_t
qeth_l3_dev_rxip_add_store(const char *buf
, size_t count
,
903 struct qeth_card
*card
, enum qeth_prot_versions proto
)
908 mutex_lock(&card
->conf_mutex
);
909 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
911 rc
= qeth_l3_add_rxip(card
, proto
, addr
);
912 mutex_unlock(&card
->conf_mutex
);
913 return rc
? rc
: count
;
916 static ssize_t
qeth_l3_dev_rxip_add4_store(struct device
*dev
,
917 struct device_attribute
*attr
, const char *buf
, size_t count
)
919 struct qeth_card
*card
= dev_get_drvdata(dev
);
924 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
927 static QETH_DEVICE_ATTR(rxip_add4
, add4
, 0644,
928 qeth_l3_dev_rxip_add4_show
,
929 qeth_l3_dev_rxip_add4_store
);
931 static ssize_t
qeth_l3_dev_rxip_del_store(const char *buf
, size_t count
,
932 struct qeth_card
*card
, enum qeth_prot_versions proto
)
937 mutex_lock(&card
->conf_mutex
);
938 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
940 qeth_l3_del_rxip(card
, proto
, addr
);
941 mutex_unlock(&card
->conf_mutex
);
942 return rc
? rc
: count
;
945 static ssize_t
qeth_l3_dev_rxip_del4_store(struct device
*dev
,
946 struct device_attribute
*attr
, const char *buf
, size_t count
)
948 struct qeth_card
*card
= dev_get_drvdata(dev
);
953 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
956 static QETH_DEVICE_ATTR(rxip_del4
, del4
, 0200, NULL
,
957 qeth_l3_dev_rxip_del4_store
);
959 static ssize_t
qeth_l3_dev_rxip_add6_show(struct device
*dev
,
960 struct device_attribute
*attr
, char *buf
)
962 struct qeth_card
*card
= dev_get_drvdata(dev
);
967 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV6
);
970 static ssize_t
qeth_l3_dev_rxip_add6_store(struct device
*dev
,
971 struct device_attribute
*attr
, const char *buf
, size_t count
)
973 struct qeth_card
*card
= dev_get_drvdata(dev
);
978 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
981 static QETH_DEVICE_ATTR(rxip_add6
, add6
, 0644,
982 qeth_l3_dev_rxip_add6_show
,
983 qeth_l3_dev_rxip_add6_store
);
985 static ssize_t
qeth_l3_dev_rxip_del6_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_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
996 static QETH_DEVICE_ATTR(rxip_del6
, del6
, 0200, NULL
,
997 qeth_l3_dev_rxip_del6_store
);
999 static struct attribute
*qeth_rxip_device_attrs
[] = {
1000 &dev_attr_rxip_add4
.attr
,
1001 &dev_attr_rxip_del4
.attr
,
1002 &dev_attr_rxip_add6
.attr
,
1003 &dev_attr_rxip_del6
.attr
,
1007 static struct attribute_group qeth_device_rxip_group
= {
1009 .attrs
= qeth_rxip_device_attrs
,
1012 int qeth_l3_create_device_attributes(struct device
*dev
)
1016 ret
= sysfs_create_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1020 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_ipato_group
);
1022 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1026 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_vipa_group
);
1028 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1029 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1033 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_rxip_group
);
1035 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1036 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1037 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1043 void qeth_l3_remove_device_attributes(struct device
*dev
)
1045 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1046 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1047 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1048 sysfs_remove_group(&dev
->kobj
, &qeth_device_rxip_group
);