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
;
63 tmp
= strsep((char **) &buf
, "\n");
64 mutex_lock(&card
->conf_mutex
);
65 if (!strcmp(tmp
, "no_router")) {
66 route
->type
= NO_ROUTER
;
67 } else if (!strcmp(tmp
, "primary_connector")) {
68 route
->type
= PRIMARY_CONNECTOR
;
69 } else if (!strcmp(tmp
, "secondary_connector")) {
70 route
->type
= SECONDARY_CONNECTOR
;
71 } else if (!strcmp(tmp
, "primary_router")) {
72 route
->type
= PRIMARY_ROUTER
;
73 } else if (!strcmp(tmp
, "secondary_router")) {
74 route
->type
= SECONDARY_ROUTER
;
75 } else if (!strcmp(tmp
, "multicast_router")) {
76 route
->type
= MULTICAST_ROUTER
;
81 if (((card
->state
== CARD_STATE_SOFTSETUP
) ||
82 (card
->state
== CARD_STATE_UP
)) &&
83 (old_route_type
!= route
->type
)) {
84 if (prot
== QETH_PROT_IPV4
)
85 rc
= qeth_l3_setrouting_v4(card
);
86 else if (prot
== QETH_PROT_IPV6
)
87 rc
= qeth_l3_setrouting_v6(card
);
91 route
->type
= old_route_type
;
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_sniffer_show(struct device
*dev
,
179 struct device_attribute
*attr
, char *buf
)
181 struct qeth_card
*card
= dev_get_drvdata(dev
);
186 return sprintf(buf
, "%i\n", card
->options
.sniffer
? 1 : 0);
189 static ssize_t
qeth_l3_dev_sniffer_store(struct device
*dev
,
190 struct device_attribute
*attr
, const char *buf
, size_t count
)
192 struct qeth_card
*card
= dev_get_drvdata(dev
);
199 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
201 if (card
->options
.cq
== QETH_CQ_ENABLED
)
204 mutex_lock(&card
->conf_mutex
);
205 if ((card
->state
!= CARD_STATE_DOWN
) &&
206 (card
->state
!= CARD_STATE_RECOVER
)) {
211 rc
= strict_strtoul(buf
, 16, &i
);
218 card
->options
.sniffer
= i
;
221 qdio_get_ssqd_desc(CARD_DDEV(card
), &card
->ssqd
);
222 if (card
->ssqd
.qdioac2
& QETH_SNIFF_AVAIL
) {
223 card
->options
.sniffer
= i
;
224 if (card
->qdio
.init_pool
.buf_count
!=
225 QETH_IN_BUF_COUNT_MAX
)
226 qeth_realloc_buffer_pool(card
,
227 QETH_IN_BUF_COUNT_MAX
);
235 mutex_unlock(&card
->conf_mutex
);
236 return rc
? rc
: count
;
239 static DEVICE_ATTR(sniffer
, 0644, qeth_l3_dev_sniffer_show
,
240 qeth_l3_dev_sniffer_store
);
243 static ssize_t
qeth_l3_dev_hsuid_show(struct device
*dev
,
244 struct device_attribute
*attr
, char *buf
)
246 struct qeth_card
*card
= dev_get_drvdata(dev
);
252 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
255 if (card
->state
== CARD_STATE_DOWN
)
258 memcpy(tmp_hsuid
, card
->options
.hsuid
, sizeof(tmp_hsuid
));
259 EBCASC(tmp_hsuid
, 8);
260 return sprintf(buf
, "%s\n", tmp_hsuid
);
263 static ssize_t
qeth_l3_dev_hsuid_store(struct device
*dev
,
264 struct device_attribute
*attr
, const char *buf
, size_t count
)
266 struct qeth_card
*card
= dev_get_drvdata(dev
);
267 struct qeth_ipaddr
*addr
;
274 if (card
->info
.type
!= QETH_CARD_TYPE_IQD
)
276 if (card
->state
!= CARD_STATE_DOWN
&&
277 card
->state
!= CARD_STATE_RECOVER
)
279 if (card
->options
.sniffer
)
281 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
)
284 tmp
= strsep((char **)&buf
, "\n");
288 if (card
->options
.hsuid
[0]) {
289 /* delete old ip address */
290 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
;
301 if (!qeth_l3_delete_ip(card
, addr
))
303 qeth_l3_set_ip_addr_list(card
);
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 for (i
= 0; i
< 8; i
++)
319 card
->options
.hsuid
[i
] = ' ';
320 card
->options
.hsuid
[8] = '\0';
321 strncpy(card
->options
.hsuid
, tmp
, strlen(tmp
));
322 ASCEBC(card
->options
.hsuid
, 8);
324 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
326 addr
= qeth_l3_get_addr_buffer(QETH_PROT_IPV6
);
328 addr
->u
.a6
.addr
.s6_addr32
[0] = 0xfe800000;
329 addr
->u
.a6
.addr
.s6_addr32
[1] = 0x00000000;
330 for (i
= 8; i
< 16; i
++)
331 addr
->u
.a6
.addr
.s6_addr
[i
] = card
->options
.hsuid
[i
- 8];
332 addr
->u
.a6
.pfxlen
= 0;
333 addr
->type
= QETH_IP_TYPE_NORMAL
;
336 if (!qeth_l3_add_ip(card
, addr
))
338 qeth_l3_set_ip_addr_list(card
);
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
*tmpipa
, *t
;
382 mutex_lock(&card
->conf_mutex
);
383 if ((card
->state
!= CARD_STATE_DOWN
) &&
384 (card
->state
!= CARD_STATE_RECOVER
)) {
389 tmp
= strsep((char **) &buf
, "\n");
390 if (!strcmp(tmp
, "toggle")) {
391 card
->ipato
.enabled
= (card
->ipato
.enabled
)? 0 : 1;
392 } else if (!strcmp(tmp
, "1")) {
393 card
->ipato
.enabled
= 1;
394 list_for_each_entry_safe(tmpipa
, t
, card
->ip_tbd_list
, entry
) {
395 if ((tmpipa
->type
== QETH_IP_TYPE_NORMAL
) &&
396 qeth_l3_is_addr_covered_by_ipato(card
, tmpipa
))
398 QETH_IPA_SETIP_TAKEOVER_FLAG
;
401 } else if (!strcmp(tmp
, "0")) {
402 card
->ipato
.enabled
= 0;
403 list_for_each_entry_safe(tmpipa
, t
, card
->ip_tbd_list
, entry
) {
404 if (tmpipa
->set_flags
&
405 QETH_IPA_SETIP_TAKEOVER_FLAG
)
407 ~QETH_IPA_SETIP_TAKEOVER_FLAG
;
412 mutex_unlock(&card
->conf_mutex
);
413 return rc
? rc
: count
;
416 static QETH_DEVICE_ATTR(ipato_enable
, enable
, 0644,
417 qeth_l3_dev_ipato_enable_show
,
418 qeth_l3_dev_ipato_enable_store
);
420 static ssize_t
qeth_l3_dev_ipato_invert4_show(struct device
*dev
,
421 struct device_attribute
*attr
, char *buf
)
423 struct qeth_card
*card
= dev_get_drvdata(dev
);
428 return sprintf(buf
, "%i\n", card
->ipato
.invert4
? 1:0);
431 static ssize_t
qeth_l3_dev_ipato_invert4_store(struct device
*dev
,
432 struct device_attribute
*attr
,
433 const char *buf
, size_t count
)
435 struct qeth_card
*card
= dev_get_drvdata(dev
);
442 mutex_lock(&card
->conf_mutex
);
443 tmp
= strsep((char **) &buf
, "\n");
444 if (!strcmp(tmp
, "toggle")) {
445 card
->ipato
.invert4
= (card
->ipato
.invert4
)? 0 : 1;
446 } else if (!strcmp(tmp
, "1")) {
447 card
->ipato
.invert4
= 1;
448 } else if (!strcmp(tmp
, "0")) {
449 card
->ipato
.invert4
= 0;
452 mutex_unlock(&card
->conf_mutex
);
453 return rc
? rc
: count
;
456 static QETH_DEVICE_ATTR(ipato_invert4
, invert4
, 0644,
457 qeth_l3_dev_ipato_invert4_show
,
458 qeth_l3_dev_ipato_invert4_store
);
460 static ssize_t
qeth_l3_dev_ipato_add_show(char *buf
, struct qeth_card
*card
,
461 enum qeth_prot_versions proto
)
463 struct qeth_ipato_entry
*ipatoe
;
466 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
469 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
470 /* add strlen for "/<mask>\n" */
471 entry_len
+= (proto
== QETH_PROT_IPV4
)? 5 : 6;
472 spin_lock_irqsave(&card
->ip_lock
, flags
);
473 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
474 if (ipatoe
->proto
!= proto
)
476 /* String must not be longer than PAGE_SIZE. So we check if
477 * string length gets near PAGE_SIZE. Then we can savely display
478 * the next IPv6 address (worst case, compared to IPv4) */
479 if ((PAGE_SIZE
- i
) <= entry_len
)
481 qeth_l3_ipaddr_to_string(proto
, ipatoe
->addr
, addr_str
);
482 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
,
483 "%s/%i\n", addr_str
, ipatoe
->mask_bits
);
485 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
486 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
491 static ssize_t
qeth_l3_dev_ipato_add4_show(struct device
*dev
,
492 struct device_attribute
*attr
, char *buf
)
494 struct qeth_card
*card
= dev_get_drvdata(dev
);
499 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV4
);
502 static int qeth_l3_parse_ipatoe(const char *buf
, enum qeth_prot_versions proto
,
503 u8
*addr
, int *mask_bits
)
505 const char *start
, *end
;
507 char buffer
[40] = {0, };
510 /* get address string */
511 end
= strchr(start
, '/');
512 if (!end
|| (end
- start
>= 40)) {
515 strncpy(buffer
, start
, end
- start
);
516 if (qeth_l3_string_to_ipaddr(buffer
, proto
, addr
)) {
520 *mask_bits
= simple_strtoul(start
, &tmp
, 10);
521 if (!strlen(start
) ||
523 (*mask_bits
> ((proto
== QETH_PROT_IPV4
) ? 32 : 128))) {
529 static ssize_t
qeth_l3_dev_ipato_add_store(const char *buf
, size_t count
,
530 struct qeth_card
*card
, enum qeth_prot_versions proto
)
532 struct qeth_ipato_entry
*ipatoe
;
537 mutex_lock(&card
->conf_mutex
);
538 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
542 ipatoe
= kzalloc(sizeof(struct qeth_ipato_entry
), GFP_KERNEL
);
547 ipatoe
->proto
= proto
;
548 memcpy(ipatoe
->addr
, addr
, (proto
== QETH_PROT_IPV4
)? 4:16);
549 ipatoe
->mask_bits
= mask_bits
;
551 rc
= qeth_l3_add_ipato_entry(card
, ipatoe
);
555 mutex_unlock(&card
->conf_mutex
);
556 return rc
? rc
: count
;
559 static ssize_t
qeth_l3_dev_ipato_add4_store(struct device
*dev
,
560 struct device_attribute
*attr
, const char *buf
, size_t count
)
562 struct qeth_card
*card
= dev_get_drvdata(dev
);
567 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
570 static QETH_DEVICE_ATTR(ipato_add4
, add4
, 0644,
571 qeth_l3_dev_ipato_add4_show
,
572 qeth_l3_dev_ipato_add4_store
);
574 static ssize_t
qeth_l3_dev_ipato_del_store(const char *buf
, size_t count
,
575 struct qeth_card
*card
, enum qeth_prot_versions proto
)
581 mutex_lock(&card
->conf_mutex
);
582 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
584 qeth_l3_del_ipato_entry(card
, proto
, addr
, mask_bits
);
585 mutex_unlock(&card
->conf_mutex
);
586 return rc
? rc
: count
;
589 static ssize_t
qeth_l3_dev_ipato_del4_store(struct device
*dev
,
590 struct device_attribute
*attr
, const char *buf
, size_t count
)
592 struct qeth_card
*card
= dev_get_drvdata(dev
);
597 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
600 static QETH_DEVICE_ATTR(ipato_del4
, del4
, 0200, NULL
,
601 qeth_l3_dev_ipato_del4_store
);
603 static ssize_t
qeth_l3_dev_ipato_invert6_show(struct device
*dev
,
604 struct device_attribute
*attr
, char *buf
)
606 struct qeth_card
*card
= dev_get_drvdata(dev
);
611 return sprintf(buf
, "%i\n", card
->ipato
.invert6
? 1:0);
614 static ssize_t
qeth_l3_dev_ipato_invert6_store(struct device
*dev
,
615 struct device_attribute
*attr
, const char *buf
, size_t count
)
617 struct qeth_card
*card
= dev_get_drvdata(dev
);
624 mutex_lock(&card
->conf_mutex
);
625 tmp
= strsep((char **) &buf
, "\n");
626 if (!strcmp(tmp
, "toggle")) {
627 card
->ipato
.invert6
= (card
->ipato
.invert6
)? 0 : 1;
628 } else if (!strcmp(tmp
, "1")) {
629 card
->ipato
.invert6
= 1;
630 } else if (!strcmp(tmp
, "0")) {
631 card
->ipato
.invert6
= 0;
634 mutex_unlock(&card
->conf_mutex
);
635 return rc
? rc
: count
;
638 static QETH_DEVICE_ATTR(ipato_invert6
, invert6
, 0644,
639 qeth_l3_dev_ipato_invert6_show
,
640 qeth_l3_dev_ipato_invert6_store
);
643 static ssize_t
qeth_l3_dev_ipato_add6_show(struct device
*dev
,
644 struct device_attribute
*attr
, char *buf
)
646 struct qeth_card
*card
= dev_get_drvdata(dev
);
651 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV6
);
654 static ssize_t
qeth_l3_dev_ipato_add6_store(struct device
*dev
,
655 struct device_attribute
*attr
, const char *buf
, size_t count
)
657 struct qeth_card
*card
= dev_get_drvdata(dev
);
662 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
665 static QETH_DEVICE_ATTR(ipato_add6
, add6
, 0644,
666 qeth_l3_dev_ipato_add6_show
,
667 qeth_l3_dev_ipato_add6_store
);
669 static ssize_t
qeth_l3_dev_ipato_del6_store(struct device
*dev
,
670 struct device_attribute
*attr
, const char *buf
, size_t count
)
672 struct qeth_card
*card
= dev_get_drvdata(dev
);
677 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
680 static QETH_DEVICE_ATTR(ipato_del6
, del6
, 0200, NULL
,
681 qeth_l3_dev_ipato_del6_store
);
683 static struct attribute
*qeth_ipato_device_attrs
[] = {
684 &dev_attr_ipato_enable
.attr
,
685 &dev_attr_ipato_invert4
.attr
,
686 &dev_attr_ipato_add4
.attr
,
687 &dev_attr_ipato_del4
.attr
,
688 &dev_attr_ipato_invert6
.attr
,
689 &dev_attr_ipato_add6
.attr
,
690 &dev_attr_ipato_del6
.attr
,
694 static struct attribute_group qeth_device_ipato_group
= {
695 .name
= "ipa_takeover",
696 .attrs
= qeth_ipato_device_attrs
,
699 static ssize_t
qeth_l3_dev_vipa_add_show(char *buf
, struct qeth_card
*card
,
700 enum qeth_prot_versions proto
)
702 struct qeth_ipaddr
*ipaddr
;
704 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
708 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
709 entry_len
+= 2; /* \n + terminator */
710 spin_lock_irqsave(&card
->ip_lock
, flags
);
711 list_for_each_entry(ipaddr
, &card
->ip_list
, entry
) {
712 if (ipaddr
->proto
!= proto
)
714 if (ipaddr
->type
!= QETH_IP_TYPE_VIPA
)
716 /* String must not be longer than PAGE_SIZE. So we check if
717 * string length gets near PAGE_SIZE. Then we can savely display
718 * the next IPv6 address (worst case, compared to IPv4) */
719 if ((PAGE_SIZE
- i
) <= entry_len
)
721 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
723 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
725 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
726 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
731 static ssize_t
qeth_l3_dev_vipa_add4_show(struct device
*dev
,
732 struct device_attribute
*attr
, char *buf
)
734 struct qeth_card
*card
= dev_get_drvdata(dev
);
739 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV4
);
742 static int qeth_l3_parse_vipae(const char *buf
, enum qeth_prot_versions proto
,
745 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
751 static ssize_t
qeth_l3_dev_vipa_add_store(const char *buf
, size_t count
,
752 struct qeth_card
*card
, enum qeth_prot_versions proto
)
757 mutex_lock(&card
->conf_mutex
);
758 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
760 rc
= qeth_l3_add_vipa(card
, proto
, addr
);
761 mutex_unlock(&card
->conf_mutex
);
762 return rc
? rc
: count
;
765 static ssize_t
qeth_l3_dev_vipa_add4_store(struct device
*dev
,
766 struct device_attribute
*attr
, const char *buf
, size_t count
)
768 struct qeth_card
*card
= dev_get_drvdata(dev
);
773 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
776 static QETH_DEVICE_ATTR(vipa_add4
, add4
, 0644,
777 qeth_l3_dev_vipa_add4_show
,
778 qeth_l3_dev_vipa_add4_store
);
780 static ssize_t
qeth_l3_dev_vipa_del_store(const char *buf
, size_t count
,
781 struct qeth_card
*card
, enum qeth_prot_versions proto
)
786 mutex_lock(&card
->conf_mutex
);
787 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
789 qeth_l3_del_vipa(card
, proto
, addr
);
790 mutex_unlock(&card
->conf_mutex
);
791 return rc
? rc
: count
;
794 static ssize_t
qeth_l3_dev_vipa_del4_store(struct device
*dev
,
795 struct device_attribute
*attr
, const char *buf
, size_t count
)
797 struct qeth_card
*card
= dev_get_drvdata(dev
);
802 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
805 static QETH_DEVICE_ATTR(vipa_del4
, del4
, 0200, NULL
,
806 qeth_l3_dev_vipa_del4_store
);
808 static ssize_t
qeth_l3_dev_vipa_add6_show(struct device
*dev
,
809 struct device_attribute
*attr
, char *buf
)
811 struct qeth_card
*card
= dev_get_drvdata(dev
);
816 return qeth_l3_dev_vipa_add_show(buf
, card
, QETH_PROT_IPV6
);
819 static ssize_t
qeth_l3_dev_vipa_add6_store(struct device
*dev
,
820 struct device_attribute
*attr
, const char *buf
, size_t count
)
822 struct qeth_card
*card
= dev_get_drvdata(dev
);
827 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
830 static QETH_DEVICE_ATTR(vipa_add6
, add6
, 0644,
831 qeth_l3_dev_vipa_add6_show
,
832 qeth_l3_dev_vipa_add6_store
);
834 static ssize_t
qeth_l3_dev_vipa_del6_store(struct device
*dev
,
835 struct device_attribute
*attr
, const char *buf
, size_t count
)
837 struct qeth_card
*card
= dev_get_drvdata(dev
);
842 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
845 static QETH_DEVICE_ATTR(vipa_del6
, del6
, 0200, NULL
,
846 qeth_l3_dev_vipa_del6_store
);
848 static struct attribute
*qeth_vipa_device_attrs
[] = {
849 &dev_attr_vipa_add4
.attr
,
850 &dev_attr_vipa_del4
.attr
,
851 &dev_attr_vipa_add6
.attr
,
852 &dev_attr_vipa_del6
.attr
,
856 static struct attribute_group qeth_device_vipa_group
= {
858 .attrs
= qeth_vipa_device_attrs
,
861 static ssize_t
qeth_l3_dev_rxip_add_show(char *buf
, struct qeth_card
*card
,
862 enum qeth_prot_versions proto
)
864 struct qeth_ipaddr
*ipaddr
;
866 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
870 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
871 entry_len
+= 2; /* \n + terminator */
872 spin_lock_irqsave(&card
->ip_lock
, flags
);
873 list_for_each_entry(ipaddr
, &card
->ip_list
, entry
) {
874 if (ipaddr
->proto
!= proto
)
876 if (ipaddr
->type
!= QETH_IP_TYPE_RXIP
)
878 /* String must not be longer than PAGE_SIZE. So we check if
879 * string length gets near PAGE_SIZE. Then we can savely display
880 * the next IPv6 address (worst case, compared to IPv4) */
881 if ((PAGE_SIZE
- i
) <= entry_len
)
883 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
885 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n", addr_str
);
887 spin_unlock_irqrestore(&card
->ip_lock
, flags
);
888 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
893 static ssize_t
qeth_l3_dev_rxip_add4_show(struct device
*dev
,
894 struct device_attribute
*attr
, char *buf
)
896 struct qeth_card
*card
= dev_get_drvdata(dev
);
901 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV4
);
904 static int qeth_l3_parse_rxipe(const char *buf
, enum qeth_prot_versions proto
,
907 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
913 static ssize_t
qeth_l3_dev_rxip_add_store(const char *buf
, size_t count
,
914 struct qeth_card
*card
, enum qeth_prot_versions proto
)
919 mutex_lock(&card
->conf_mutex
);
920 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
922 rc
= qeth_l3_add_rxip(card
, proto
, addr
);
923 mutex_unlock(&card
->conf_mutex
);
924 return rc
? rc
: count
;
927 static ssize_t
qeth_l3_dev_rxip_add4_store(struct device
*dev
,
928 struct device_attribute
*attr
, const char *buf
, size_t count
)
930 struct qeth_card
*card
= dev_get_drvdata(dev
);
935 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
938 static QETH_DEVICE_ATTR(rxip_add4
, add4
, 0644,
939 qeth_l3_dev_rxip_add4_show
,
940 qeth_l3_dev_rxip_add4_store
);
942 static ssize_t
qeth_l3_dev_rxip_del_store(const char *buf
, size_t count
,
943 struct qeth_card
*card
, enum qeth_prot_versions proto
)
948 mutex_lock(&card
->conf_mutex
);
949 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
951 qeth_l3_del_rxip(card
, proto
, addr
);
952 mutex_unlock(&card
->conf_mutex
);
953 return rc
? rc
: count
;
956 static ssize_t
qeth_l3_dev_rxip_del4_store(struct device
*dev
,
957 struct device_attribute
*attr
, const char *buf
, size_t count
)
959 struct qeth_card
*card
= dev_get_drvdata(dev
);
964 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
967 static QETH_DEVICE_ATTR(rxip_del4
, del4
, 0200, NULL
,
968 qeth_l3_dev_rxip_del4_store
);
970 static ssize_t
qeth_l3_dev_rxip_add6_show(struct device
*dev
,
971 struct device_attribute
*attr
, char *buf
)
973 struct qeth_card
*card
= dev_get_drvdata(dev
);
978 return qeth_l3_dev_rxip_add_show(buf
, card
, QETH_PROT_IPV6
);
981 static ssize_t
qeth_l3_dev_rxip_add6_store(struct device
*dev
,
982 struct device_attribute
*attr
, const char *buf
, size_t count
)
984 struct qeth_card
*card
= dev_get_drvdata(dev
);
989 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
992 static QETH_DEVICE_ATTR(rxip_add6
, add6
, 0644,
993 qeth_l3_dev_rxip_add6_show
,
994 qeth_l3_dev_rxip_add6_store
);
996 static ssize_t
qeth_l3_dev_rxip_del6_store(struct device
*dev
,
997 struct device_attribute
*attr
, const char *buf
, size_t count
)
999 struct qeth_card
*card
= dev_get_drvdata(dev
);
1004 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
1007 static QETH_DEVICE_ATTR(rxip_del6
, del6
, 0200, NULL
,
1008 qeth_l3_dev_rxip_del6_store
);
1010 static struct attribute
*qeth_rxip_device_attrs
[] = {
1011 &dev_attr_rxip_add4
.attr
,
1012 &dev_attr_rxip_del4
.attr
,
1013 &dev_attr_rxip_add6
.attr
,
1014 &dev_attr_rxip_del6
.attr
,
1018 static struct attribute_group qeth_device_rxip_group
= {
1020 .attrs
= qeth_rxip_device_attrs
,
1023 int qeth_l3_create_device_attributes(struct device
*dev
)
1027 ret
= sysfs_create_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1031 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_ipato_group
);
1033 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1037 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_vipa_group
);
1039 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1040 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1044 ret
= sysfs_create_group(&dev
->kobj
, &qeth_device_rxip_group
);
1046 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1047 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1048 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1054 void qeth_l3_remove_device_attributes(struct device
*dev
)
1056 sysfs_remove_group(&dev
->kobj
, &qeth_l3_device_attr_group
);
1057 sysfs_remove_group(&dev
->kobj
, &qeth_device_ipato_group
);
1058 sysfs_remove_group(&dev
->kobj
, &qeth_device_vipa_group
);
1059 sysfs_remove_group(&dev
->kobj
, &qeth_device_rxip_group
);