1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2007
4 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
10 #include <linux/slab.h>
11 #include <asm/ebcdic.h>
12 #include <linux/hashtable.h>
13 #include <linux/inet.h>
16 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
17 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
19 static int qeth_l3_string_to_ipaddr(const char *buf
,
20 enum qeth_prot_versions proto
, u8
*addr
)
24 if ((proto
== QETH_PROT_IPV4
&& !in4_pton(buf
, -1, addr
, -1, &end
)) ||
25 (proto
== QETH_PROT_IPV6
&& !in6_pton(buf
, -1, addr
, -1, &end
)))
30 static ssize_t
qeth_l3_dev_route_show(struct qeth_card
*card
,
31 struct qeth_routing_info
*route
, char *buf
)
33 switch (route
->type
) {
35 return sprintf(buf
, "%s\n", "primary router");
36 case SECONDARY_ROUTER
:
37 return sprintf(buf
, "%s\n", "secondary router");
38 case MULTICAST_ROUTER
:
39 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
40 return sprintf(buf
, "%s\n", "multicast router+");
42 return sprintf(buf
, "%s\n", "multicast router");
43 case PRIMARY_CONNECTOR
:
44 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
45 return sprintf(buf
, "%s\n", "primary connector+");
47 return sprintf(buf
, "%s\n", "primary connector");
48 case SECONDARY_CONNECTOR
:
49 if (card
->info
.broadcast_capable
== QETH_BROADCAST_WITHOUT_ECHO
)
50 return sprintf(buf
, "%s\n", "secondary connector+");
52 return sprintf(buf
, "%s\n", "secondary connector");
54 return sprintf(buf
, "%s\n", "no");
58 static ssize_t
qeth_l3_dev_route4_show(struct device
*dev
,
59 struct device_attribute
*attr
, char *buf
)
61 struct qeth_card
*card
= dev_get_drvdata(dev
);
63 return qeth_l3_dev_route_show(card
, &card
->options
.route4
, buf
);
66 static ssize_t
qeth_l3_dev_route_store(struct qeth_card
*card
,
67 struct qeth_routing_info
*route
, enum qeth_prot_versions prot
,
68 const char *buf
, size_t count
)
70 enum qeth_routing_types old_route_type
= route
->type
;
73 mutex_lock(&card
->conf_mutex
);
74 if (sysfs_streq(buf
, "no_router")) {
75 route
->type
= NO_ROUTER
;
76 } else if (sysfs_streq(buf
, "primary_connector")) {
77 route
->type
= PRIMARY_CONNECTOR
;
78 } else if (sysfs_streq(buf
, "secondary_connector")) {
79 route
->type
= SECONDARY_CONNECTOR
;
80 } else if (sysfs_streq(buf
, "primary_router")) {
81 route
->type
= PRIMARY_ROUTER
;
82 } else if (sysfs_streq(buf
, "secondary_router")) {
83 route
->type
= SECONDARY_ROUTER
;
84 } else if (sysfs_streq(buf
, "multicast_router")) {
85 route
->type
= MULTICAST_ROUTER
;
90 if (qeth_card_hw_is_reachable(card
) &&
91 (old_route_type
!= route
->type
)) {
92 if (prot
== QETH_PROT_IPV4
)
93 rc
= qeth_l3_setrouting_v4(card
);
94 else if (prot
== QETH_PROT_IPV6
)
95 rc
= qeth_l3_setrouting_v6(card
);
99 route
->type
= old_route_type
;
100 mutex_unlock(&card
->conf_mutex
);
101 return rc
? rc
: count
;
104 static ssize_t
qeth_l3_dev_route4_store(struct device
*dev
,
105 struct device_attribute
*attr
, const char *buf
, size_t count
)
107 struct qeth_card
*card
= dev_get_drvdata(dev
);
109 return qeth_l3_dev_route_store(card
, &card
->options
.route4
,
110 QETH_PROT_IPV4
, buf
, count
);
113 static DEVICE_ATTR(route4
, 0644, qeth_l3_dev_route4_show
,
114 qeth_l3_dev_route4_store
);
116 static ssize_t
qeth_l3_dev_route6_show(struct device
*dev
,
117 struct device_attribute
*attr
, char *buf
)
119 struct qeth_card
*card
= dev_get_drvdata(dev
);
121 return qeth_l3_dev_route_show(card
, &card
->options
.route6
, buf
);
124 static ssize_t
qeth_l3_dev_route6_store(struct device
*dev
,
125 struct device_attribute
*attr
, const char *buf
, size_t count
)
127 struct qeth_card
*card
= dev_get_drvdata(dev
);
129 return qeth_l3_dev_route_store(card
, &card
->options
.route6
,
130 QETH_PROT_IPV6
, buf
, count
);
133 static DEVICE_ATTR(route6
, 0644, qeth_l3_dev_route6_show
,
134 qeth_l3_dev_route6_store
);
136 static ssize_t
qeth_l3_dev_fake_broadcast_show(struct device
*dev
,
137 struct device_attribute
*attr
, char *buf
)
139 struct qeth_card
*card
= dev_get_drvdata(dev
);
141 return sprintf(buf
, "%i\n", card
->options
.fake_broadcast
? 1:0);
144 static ssize_t
qeth_l3_dev_fake_broadcast_store(struct device
*dev
,
145 struct device_attribute
*attr
, const char *buf
, size_t count
)
147 struct qeth_card
*card
= dev_get_drvdata(dev
);
151 mutex_lock(&card
->conf_mutex
);
152 if (card
->state
!= CARD_STATE_DOWN
) {
157 i
= simple_strtoul(buf
, &tmp
, 16);
158 if ((i
== 0) || (i
== 1))
159 card
->options
.fake_broadcast
= i
;
163 mutex_unlock(&card
->conf_mutex
);
164 return rc
? rc
: count
;
167 static DEVICE_ATTR(fake_broadcast
, 0644, qeth_l3_dev_fake_broadcast_show
,
168 qeth_l3_dev_fake_broadcast_store
);
170 static ssize_t
qeth_l3_dev_sniffer_show(struct device
*dev
,
171 struct device_attribute
*attr
, char *buf
)
173 struct qeth_card
*card
= dev_get_drvdata(dev
);
175 return sprintf(buf
, "%i\n", card
->options
.sniffer
? 1 : 0);
178 static ssize_t
qeth_l3_dev_sniffer_store(struct device
*dev
,
179 struct device_attribute
*attr
, const char *buf
, size_t count
)
181 struct qeth_card
*card
= dev_get_drvdata(dev
);
187 if (card
->options
.cq
== QETH_CQ_ENABLED
)
190 mutex_lock(&card
->conf_mutex
);
191 if (card
->state
!= CARD_STATE_DOWN
) {
196 rc
= kstrtoul(buf
, 16, &i
);
203 card
->options
.sniffer
= i
;
206 qdio_get_ssqd_desc(CARD_DDEV(card
), &card
->ssqd
);
207 if (card
->ssqd
.qdioac2
& QETH_SNIFF_AVAIL
) {
208 card
->options
.sniffer
= i
;
209 if (card
->qdio
.init_pool
.buf_count
!=
210 QETH_IN_BUF_COUNT_MAX
)
211 qeth_realloc_buffer_pool(card
,
212 QETH_IN_BUF_COUNT_MAX
);
220 mutex_unlock(&card
->conf_mutex
);
221 return rc
? rc
: count
;
224 static DEVICE_ATTR(sniffer
, 0644, qeth_l3_dev_sniffer_show
,
225 qeth_l3_dev_sniffer_store
);
227 static ssize_t
qeth_l3_dev_hsuid_show(struct device
*dev
,
228 struct device_attribute
*attr
, char *buf
)
230 struct qeth_card
*card
= dev_get_drvdata(dev
);
236 memcpy(tmp_hsuid
, card
->options
.hsuid
, sizeof(tmp_hsuid
));
237 EBCASC(tmp_hsuid
, 8);
238 return sprintf(buf
, "%s\n", tmp_hsuid
);
241 static ssize_t
qeth_l3_dev_hsuid_store(struct device
*dev
,
242 struct device_attribute
*attr
, const char *buf
, size_t count
)
244 struct qeth_card
*card
= dev_get_drvdata(dev
);
250 if (card
->state
!= CARD_STATE_DOWN
)
252 if (card
->options
.sniffer
)
254 if (card
->options
.cq
== QETH_CQ_NOTAVAILABLE
)
257 tmp
= strsep((char **)&buf
, "\n");
261 if (card
->options
.hsuid
[0])
262 /* delete old ip address */
263 qeth_l3_modify_hsuid(card
, false);
265 if (strlen(tmp
) == 0) {
266 /* delete ip address only */
267 card
->options
.hsuid
[0] = '\0';
268 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
269 qeth_configure_cq(card
, QETH_CQ_DISABLED
);
273 if (qeth_configure_cq(card
, QETH_CQ_ENABLED
))
276 snprintf(card
->options
.hsuid
, sizeof(card
->options
.hsuid
),
278 ASCEBC(card
->options
.hsuid
, 8);
279 memcpy(card
->dev
->perm_addr
, card
->options
.hsuid
, 9);
281 rc
= qeth_l3_modify_hsuid(card
, true);
283 return rc
? rc
: count
;
286 static DEVICE_ATTR(hsuid
, 0644, qeth_l3_dev_hsuid_show
,
287 qeth_l3_dev_hsuid_store
);
290 static struct attribute
*qeth_l3_device_attrs
[] = {
291 &dev_attr_route4
.attr
,
292 &dev_attr_route6
.attr
,
293 &dev_attr_fake_broadcast
.attr
,
294 &dev_attr_sniffer
.attr
,
295 &dev_attr_hsuid
.attr
,
299 static const struct attribute_group qeth_l3_device_attr_group
= {
300 .attrs
= qeth_l3_device_attrs
,
303 static ssize_t
qeth_l3_dev_ipato_enable_show(struct device
*dev
,
304 struct device_attribute
*attr
, char *buf
)
306 struct qeth_card
*card
= dev_get_drvdata(dev
);
308 return sprintf(buf
, "%i\n", card
->ipato
.enabled
? 1:0);
311 static ssize_t
qeth_l3_dev_ipato_enable_store(struct device
*dev
,
312 struct device_attribute
*attr
, const char *buf
, size_t count
)
314 struct qeth_card
*card
= dev_get_drvdata(dev
);
318 mutex_lock(&card
->conf_mutex
);
319 if (card
->state
!= CARD_STATE_DOWN
) {
324 if (sysfs_streq(buf
, "toggle")) {
325 enable
= !card
->ipato
.enabled
;
326 } else if (kstrtobool(buf
, &enable
)) {
331 if (card
->ipato
.enabled
!= enable
) {
332 card
->ipato
.enabled
= enable
;
333 mutex_lock(&card
->ip_lock
);
334 qeth_l3_update_ipato(card
);
335 mutex_unlock(&card
->ip_lock
);
338 mutex_unlock(&card
->conf_mutex
);
339 return rc
? rc
: count
;
342 static QETH_DEVICE_ATTR(ipato_enable
, enable
, 0644,
343 qeth_l3_dev_ipato_enable_show
,
344 qeth_l3_dev_ipato_enable_store
);
346 static ssize_t
qeth_l3_dev_ipato_invert4_show(struct device
*dev
,
347 struct device_attribute
*attr
, char *buf
)
349 struct qeth_card
*card
= dev_get_drvdata(dev
);
351 return sprintf(buf
, "%i\n", card
->ipato
.invert4
? 1:0);
354 static ssize_t
qeth_l3_dev_ipato_invert4_store(struct device
*dev
,
355 struct device_attribute
*attr
,
356 const char *buf
, size_t count
)
358 struct qeth_card
*card
= dev_get_drvdata(dev
);
362 mutex_lock(&card
->conf_mutex
);
363 if (sysfs_streq(buf
, "toggle")) {
364 invert
= !card
->ipato
.invert4
;
365 } else if (kstrtobool(buf
, &invert
)) {
370 if (card
->ipato
.invert4
!= invert
) {
371 card
->ipato
.invert4
= invert
;
372 mutex_lock(&card
->ip_lock
);
373 qeth_l3_update_ipato(card
);
374 mutex_unlock(&card
->ip_lock
);
377 mutex_unlock(&card
->conf_mutex
);
378 return rc
? rc
: count
;
381 static QETH_DEVICE_ATTR(ipato_invert4
, invert4
, 0644,
382 qeth_l3_dev_ipato_invert4_show
,
383 qeth_l3_dev_ipato_invert4_store
);
385 static ssize_t
qeth_l3_dev_ipato_add_show(char *buf
, struct qeth_card
*card
,
386 enum qeth_prot_versions proto
)
388 struct qeth_ipato_entry
*ipatoe
;
390 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
393 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
394 /* add strlen for "/<mask>\n" */
395 entry_len
+= (proto
== QETH_PROT_IPV4
)? 5 : 6;
396 mutex_lock(&card
->ip_lock
);
397 list_for_each_entry(ipatoe
, &card
->ipato
.entries
, entry
) {
398 if (ipatoe
->proto
!= proto
)
400 /* String must not be longer than PAGE_SIZE. So we check if
401 * string length gets near PAGE_SIZE. Then we can savely display
402 * the next IPv6 address (worst case, compared to IPv4) */
403 if ((PAGE_SIZE
- i
) <= entry_len
)
405 qeth_l3_ipaddr_to_string(proto
, ipatoe
->addr
, addr_str
);
406 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
,
407 "%s/%i\n", addr_str
, ipatoe
->mask_bits
);
409 mutex_unlock(&card
->ip_lock
);
410 i
+= snprintf(buf
+ i
, PAGE_SIZE
- i
, "\n");
415 static ssize_t
qeth_l3_dev_ipato_add4_show(struct device
*dev
,
416 struct device_attribute
*attr
, char *buf
)
418 struct qeth_card
*card
= dev_get_drvdata(dev
);
420 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV4
);
423 static int qeth_l3_parse_ipatoe(const char *buf
, enum qeth_prot_versions proto
,
424 u8
*addr
, int *mask_bits
)
426 const char *start
, *end
;
428 char buffer
[40] = {0, };
431 /* get address string */
432 end
= strchr(start
, '/');
433 if (!end
|| (end
- start
>= 40)) {
436 strncpy(buffer
, start
, end
- start
);
437 if (qeth_l3_string_to_ipaddr(buffer
, proto
, addr
)) {
441 *mask_bits
= simple_strtoul(start
, &tmp
, 10);
442 if (!strlen(start
) ||
444 (*mask_bits
> ((proto
== QETH_PROT_IPV4
) ? 32 : 128))) {
450 static ssize_t
qeth_l3_dev_ipato_add_store(const char *buf
, size_t count
,
451 struct qeth_card
*card
, enum qeth_prot_versions proto
)
453 struct qeth_ipato_entry
*ipatoe
;
458 mutex_lock(&card
->conf_mutex
);
459 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
463 ipatoe
= kzalloc(sizeof(struct qeth_ipato_entry
), GFP_KERNEL
);
468 ipatoe
->proto
= proto
;
469 memcpy(ipatoe
->addr
, addr
, (proto
== QETH_PROT_IPV4
)? 4:16);
470 ipatoe
->mask_bits
= mask_bits
;
472 rc
= qeth_l3_add_ipato_entry(card
, ipatoe
);
476 mutex_unlock(&card
->conf_mutex
);
477 return rc
? rc
: count
;
480 static ssize_t
qeth_l3_dev_ipato_add4_store(struct device
*dev
,
481 struct device_attribute
*attr
, const char *buf
, size_t count
)
483 struct qeth_card
*card
= dev_get_drvdata(dev
);
485 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
488 static QETH_DEVICE_ATTR(ipato_add4
, add4
, 0644,
489 qeth_l3_dev_ipato_add4_show
,
490 qeth_l3_dev_ipato_add4_store
);
492 static ssize_t
qeth_l3_dev_ipato_del_store(const char *buf
, size_t count
,
493 struct qeth_card
*card
, enum qeth_prot_versions proto
)
499 mutex_lock(&card
->conf_mutex
);
500 rc
= qeth_l3_parse_ipatoe(buf
, proto
, addr
, &mask_bits
);
502 rc
= qeth_l3_del_ipato_entry(card
, proto
, addr
, mask_bits
);
503 mutex_unlock(&card
->conf_mutex
);
504 return rc
? rc
: count
;
507 static ssize_t
qeth_l3_dev_ipato_del4_store(struct device
*dev
,
508 struct device_attribute
*attr
, const char *buf
, size_t count
)
510 struct qeth_card
*card
= dev_get_drvdata(dev
);
512 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
515 static QETH_DEVICE_ATTR(ipato_del4
, del4
, 0200, NULL
,
516 qeth_l3_dev_ipato_del4_store
);
518 static ssize_t
qeth_l3_dev_ipato_invert6_show(struct device
*dev
,
519 struct device_attribute
*attr
, char *buf
)
521 struct qeth_card
*card
= dev_get_drvdata(dev
);
523 return sprintf(buf
, "%i\n", card
->ipato
.invert6
? 1:0);
526 static ssize_t
qeth_l3_dev_ipato_invert6_store(struct device
*dev
,
527 struct device_attribute
*attr
, const char *buf
, size_t count
)
529 struct qeth_card
*card
= dev_get_drvdata(dev
);
533 mutex_lock(&card
->conf_mutex
);
534 if (sysfs_streq(buf
, "toggle")) {
535 invert
= !card
->ipato
.invert6
;
536 } else if (kstrtobool(buf
, &invert
)) {
541 if (card
->ipato
.invert6
!= invert
) {
542 card
->ipato
.invert6
= invert
;
543 mutex_lock(&card
->ip_lock
);
544 qeth_l3_update_ipato(card
);
545 mutex_unlock(&card
->ip_lock
);
548 mutex_unlock(&card
->conf_mutex
);
549 return rc
? rc
: count
;
552 static QETH_DEVICE_ATTR(ipato_invert6
, invert6
, 0644,
553 qeth_l3_dev_ipato_invert6_show
,
554 qeth_l3_dev_ipato_invert6_store
);
557 static ssize_t
qeth_l3_dev_ipato_add6_show(struct device
*dev
,
558 struct device_attribute
*attr
, char *buf
)
560 struct qeth_card
*card
= dev_get_drvdata(dev
);
562 return qeth_l3_dev_ipato_add_show(buf
, card
, QETH_PROT_IPV6
);
565 static ssize_t
qeth_l3_dev_ipato_add6_store(struct device
*dev
,
566 struct device_attribute
*attr
, const char *buf
, size_t count
)
568 struct qeth_card
*card
= dev_get_drvdata(dev
);
570 return qeth_l3_dev_ipato_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
573 static QETH_DEVICE_ATTR(ipato_add6
, add6
, 0644,
574 qeth_l3_dev_ipato_add6_show
,
575 qeth_l3_dev_ipato_add6_store
);
577 static ssize_t
qeth_l3_dev_ipato_del6_store(struct device
*dev
,
578 struct device_attribute
*attr
, const char *buf
, size_t count
)
580 struct qeth_card
*card
= dev_get_drvdata(dev
);
582 return qeth_l3_dev_ipato_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
585 static QETH_DEVICE_ATTR(ipato_del6
, del6
, 0200, NULL
,
586 qeth_l3_dev_ipato_del6_store
);
588 static struct attribute
*qeth_ipato_device_attrs
[] = {
589 &dev_attr_ipato_enable
.attr
,
590 &dev_attr_ipato_invert4
.attr
,
591 &dev_attr_ipato_add4
.attr
,
592 &dev_attr_ipato_del4
.attr
,
593 &dev_attr_ipato_invert6
.attr
,
594 &dev_attr_ipato_add6
.attr
,
595 &dev_attr_ipato_del6
.attr
,
599 static const struct attribute_group qeth_device_ipato_group
= {
600 .name
= "ipa_takeover",
601 .attrs
= qeth_ipato_device_attrs
,
604 static ssize_t
qeth_l3_dev_ip_add_show(struct device
*dev
, char *buf
,
605 enum qeth_prot_versions proto
,
606 enum qeth_ip_types type
)
608 struct qeth_card
*card
= dev_get_drvdata(dev
);
609 struct qeth_ipaddr
*ipaddr
;
612 int entry_len
; /* length of 1 entry string, differs between v4 and v6 */
615 entry_len
= (proto
== QETH_PROT_IPV4
)? 12 : 40;
616 entry_len
+= 2; /* \n + terminator */
617 mutex_lock(&card
->ip_lock
);
618 hash_for_each(card
->ip_htable
, i
, ipaddr
, hnode
) {
619 if (ipaddr
->proto
!= proto
|| ipaddr
->type
!= type
)
621 /* String must not be longer than PAGE_SIZE. So we check if
622 * string length gets near PAGE_SIZE. Then we can savely display
623 * the next IPv6 address (worst case, compared to IPv4) */
624 if ((PAGE_SIZE
- str_len
) <= entry_len
)
626 qeth_l3_ipaddr_to_string(proto
, (const u8
*)&ipaddr
->u
,
628 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "%s\n",
631 mutex_unlock(&card
->ip_lock
);
632 str_len
+= snprintf(buf
+ str_len
, PAGE_SIZE
- str_len
, "\n");
637 static ssize_t
qeth_l3_dev_vipa_add4_show(struct device
*dev
,
638 struct device_attribute
*attr
,
641 return qeth_l3_dev_ip_add_show(dev
, buf
, QETH_PROT_IPV4
,
645 static int qeth_l3_parse_vipae(const char *buf
, enum qeth_prot_versions proto
,
648 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
654 static ssize_t
qeth_l3_dev_vipa_add_store(const char *buf
, size_t count
,
655 struct qeth_card
*card
, enum qeth_prot_versions proto
)
660 mutex_lock(&card
->conf_mutex
);
661 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
663 rc
= qeth_l3_modify_rxip_vipa(card
, true, addr
,
664 QETH_IP_TYPE_VIPA
, proto
);
665 mutex_unlock(&card
->conf_mutex
);
666 return rc
? rc
: count
;
669 static ssize_t
qeth_l3_dev_vipa_add4_store(struct device
*dev
,
670 struct device_attribute
*attr
, const char *buf
, size_t count
)
672 struct qeth_card
*card
= dev_get_drvdata(dev
);
674 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
677 static QETH_DEVICE_ATTR(vipa_add4
, add4
, 0644,
678 qeth_l3_dev_vipa_add4_show
,
679 qeth_l3_dev_vipa_add4_store
);
681 static ssize_t
qeth_l3_dev_vipa_del_store(const char *buf
, size_t count
,
682 struct qeth_card
*card
, enum qeth_prot_versions proto
)
687 mutex_lock(&card
->conf_mutex
);
688 rc
= qeth_l3_parse_vipae(buf
, proto
, addr
);
690 rc
= qeth_l3_modify_rxip_vipa(card
, false, addr
,
691 QETH_IP_TYPE_VIPA
, proto
);
692 mutex_unlock(&card
->conf_mutex
);
693 return rc
? rc
: count
;
696 static ssize_t
qeth_l3_dev_vipa_del4_store(struct device
*dev
,
697 struct device_attribute
*attr
, const char *buf
, size_t count
)
699 struct qeth_card
*card
= dev_get_drvdata(dev
);
701 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
704 static QETH_DEVICE_ATTR(vipa_del4
, del4
, 0200, NULL
,
705 qeth_l3_dev_vipa_del4_store
);
707 static ssize_t
qeth_l3_dev_vipa_add6_show(struct device
*dev
,
708 struct device_attribute
*attr
,
711 return qeth_l3_dev_ip_add_show(dev
, buf
, QETH_PROT_IPV6
,
715 static ssize_t
qeth_l3_dev_vipa_add6_store(struct device
*dev
,
716 struct device_attribute
*attr
, const char *buf
, size_t count
)
718 struct qeth_card
*card
= dev_get_drvdata(dev
);
720 return qeth_l3_dev_vipa_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
723 static QETH_DEVICE_ATTR(vipa_add6
, add6
, 0644,
724 qeth_l3_dev_vipa_add6_show
,
725 qeth_l3_dev_vipa_add6_store
);
727 static ssize_t
qeth_l3_dev_vipa_del6_store(struct device
*dev
,
728 struct device_attribute
*attr
, const char *buf
, size_t count
)
730 struct qeth_card
*card
= dev_get_drvdata(dev
);
732 return qeth_l3_dev_vipa_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
735 static QETH_DEVICE_ATTR(vipa_del6
, del6
, 0200, NULL
,
736 qeth_l3_dev_vipa_del6_store
);
738 static struct attribute
*qeth_vipa_device_attrs
[] = {
739 &dev_attr_vipa_add4
.attr
,
740 &dev_attr_vipa_del4
.attr
,
741 &dev_attr_vipa_add6
.attr
,
742 &dev_attr_vipa_del6
.attr
,
746 static const struct attribute_group qeth_device_vipa_group
= {
748 .attrs
= qeth_vipa_device_attrs
,
751 static ssize_t
qeth_l3_dev_rxip_add4_show(struct device
*dev
,
752 struct device_attribute
*attr
,
755 return qeth_l3_dev_ip_add_show(dev
, buf
, QETH_PROT_IPV4
,
759 static int qeth_l3_parse_rxipe(const char *buf
, enum qeth_prot_versions proto
,
763 struct in6_addr ipv6_addr
;
765 if (qeth_l3_string_to_ipaddr(buf
, proto
, addr
)) {
768 if (proto
== QETH_PROT_IPV4
) {
769 memcpy(&ipv4_addr
, addr
, sizeof(ipv4_addr
));
770 if (ipv4_is_multicast(ipv4_addr
)) {
771 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
774 } else if (proto
== QETH_PROT_IPV6
) {
775 memcpy(&ipv6_addr
, addr
, sizeof(ipv6_addr
));
776 if (ipv6_addr_is_multicast(&ipv6_addr
)) {
777 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
785 static ssize_t
qeth_l3_dev_rxip_add_store(const char *buf
, size_t count
,
786 struct qeth_card
*card
, enum qeth_prot_versions proto
)
791 mutex_lock(&card
->conf_mutex
);
792 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
794 rc
= qeth_l3_modify_rxip_vipa(card
, true, addr
,
795 QETH_IP_TYPE_RXIP
, proto
);
796 mutex_unlock(&card
->conf_mutex
);
797 return rc
? rc
: count
;
800 static ssize_t
qeth_l3_dev_rxip_add4_store(struct device
*dev
,
801 struct device_attribute
*attr
, const char *buf
, size_t count
)
803 struct qeth_card
*card
= dev_get_drvdata(dev
);
805 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV4
);
808 static QETH_DEVICE_ATTR(rxip_add4
, add4
, 0644,
809 qeth_l3_dev_rxip_add4_show
,
810 qeth_l3_dev_rxip_add4_store
);
812 static ssize_t
qeth_l3_dev_rxip_del_store(const char *buf
, size_t count
,
813 struct qeth_card
*card
, enum qeth_prot_versions proto
)
818 mutex_lock(&card
->conf_mutex
);
819 rc
= qeth_l3_parse_rxipe(buf
, proto
, addr
);
821 rc
= qeth_l3_modify_rxip_vipa(card
, false, addr
,
822 QETH_IP_TYPE_RXIP
, proto
);
823 mutex_unlock(&card
->conf_mutex
);
824 return rc
? rc
: count
;
827 static ssize_t
qeth_l3_dev_rxip_del4_store(struct device
*dev
,
828 struct device_attribute
*attr
, const char *buf
, size_t count
)
830 struct qeth_card
*card
= dev_get_drvdata(dev
);
832 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV4
);
835 static QETH_DEVICE_ATTR(rxip_del4
, del4
, 0200, NULL
,
836 qeth_l3_dev_rxip_del4_store
);
838 static ssize_t
qeth_l3_dev_rxip_add6_show(struct device
*dev
,
839 struct device_attribute
*attr
,
842 return qeth_l3_dev_ip_add_show(dev
, buf
, QETH_PROT_IPV6
,
846 static ssize_t
qeth_l3_dev_rxip_add6_store(struct device
*dev
,
847 struct device_attribute
*attr
, const char *buf
, size_t count
)
849 struct qeth_card
*card
= dev_get_drvdata(dev
);
851 return qeth_l3_dev_rxip_add_store(buf
, count
, card
, QETH_PROT_IPV6
);
854 static QETH_DEVICE_ATTR(rxip_add6
, add6
, 0644,
855 qeth_l3_dev_rxip_add6_show
,
856 qeth_l3_dev_rxip_add6_store
);
858 static ssize_t
qeth_l3_dev_rxip_del6_store(struct device
*dev
,
859 struct device_attribute
*attr
, const char *buf
, size_t count
)
861 struct qeth_card
*card
= dev_get_drvdata(dev
);
863 return qeth_l3_dev_rxip_del_store(buf
, count
, card
, QETH_PROT_IPV6
);
866 static QETH_DEVICE_ATTR(rxip_del6
, del6
, 0200, NULL
,
867 qeth_l3_dev_rxip_del6_store
);
869 static struct attribute
*qeth_rxip_device_attrs
[] = {
870 &dev_attr_rxip_add4
.attr
,
871 &dev_attr_rxip_del4
.attr
,
872 &dev_attr_rxip_add6
.attr
,
873 &dev_attr_rxip_del6
.attr
,
877 static const struct attribute_group qeth_device_rxip_group
= {
879 .attrs
= qeth_rxip_device_attrs
,
882 static const struct attribute_group
*qeth_l3_only_attr_groups
[] = {
883 &qeth_l3_device_attr_group
,
884 &qeth_device_ipato_group
,
885 &qeth_device_vipa_group
,
886 &qeth_device_rxip_group
,
890 int qeth_l3_create_device_attributes(struct device
*dev
)
892 return sysfs_create_groups(&dev
->kobj
, qeth_l3_only_attr_groups
);
895 void qeth_l3_remove_device_attributes(struct device
*dev
)
897 sysfs_remove_groups(&dev
->kobj
, qeth_l3_only_attr_groups
);
900 const struct attribute_group
*qeth_l3_attr_groups
[] = {
901 &qeth_device_attr_group
,
902 &qeth_device_blkt_group
,
903 /* l3 specific, see qeth_l3_only_attr_groups: */
904 &qeth_l3_device_attr_group
,
905 &qeth_device_ipato_group
,
906 &qeth_device_vipa_group
,
907 &qeth_device_rxip_group
,