2 * drivers/s390/net/qeth_l3_sys.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
13 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
14 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
16 static const char *qeth_l3_get_checksum_str(struct qeth_card *card)
18 if (card->options.checksum_type == SW_CHECKSUMMING)
20 else if (card->options.checksum_type == HW_CHECKSUMMING)
26 static ssize_t qeth_l3_dev_route_show(struct qeth_card *card,
27 struct qeth_routing_info *route, char *buf)
29 switch (route->type) {
31 return sprintf(buf, "%s\n", "primary router");
32 case SECONDARY_ROUTER:
33 return sprintf(buf, "%s\n", "secondary router");
34 case MULTICAST_ROUTER:
35 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
36 return sprintf(buf, "%s\n", "multicast router+");
38 return sprintf(buf, "%s\n", "multicast router");
39 case PRIMARY_CONNECTOR:
40 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
41 return sprintf(buf, "%s\n", "primary connector+");
43 return sprintf(buf, "%s\n", "primary connector");
44 case SECONDARY_CONNECTOR:
45 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
46 return sprintf(buf, "%s\n", "secondary connector+");
48 return sprintf(buf, "%s\n", "secondary connector");
50 return sprintf(buf, "%s\n", "no");
54 static ssize_t qeth_l3_dev_route4_show(struct device *dev,
55 struct device_attribute *attr, char *buf)
57 struct qeth_card *card = dev_get_drvdata(dev);
62 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
65 static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
66 struct qeth_routing_info *route, enum qeth_prot_versions prot,
67 const char *buf, size_t count)
69 enum qeth_routing_types old_route_type = route->type;
73 tmp = strsep((char **) &buf, "\n");
75 if (!strcmp(tmp, "no_router")) {
76 route->type = NO_ROUTER;
77 } else if (!strcmp(tmp, "primary_connector")) {
78 route->type = PRIMARY_CONNECTOR;
79 } else if (!strcmp(tmp, "secondary_connector")) {
80 route->type = SECONDARY_CONNECTOR;
81 } else if (!strcmp(tmp, "primary_router")) {
82 route->type = PRIMARY_ROUTER;
83 } else if (!strcmp(tmp, "secondary_router")) {
84 route->type = SECONDARY_ROUTER;
85 } else if (!strcmp(tmp, "multicast_router")) {
86 route->type = MULTICAST_ROUTER;
90 if (((card->state == CARD_STATE_SOFTSETUP) ||
91 (card->state == CARD_STATE_UP)) &&
92 (old_route_type != route->type)) {
93 if (prot == QETH_PROT_IPV4)
94 rc = qeth_l3_setrouting_v4(card);
95 else if (prot == QETH_PROT_IPV6)
96 rc = qeth_l3_setrouting_v6(card);
101 static ssize_t qeth_l3_dev_route4_store(struct device *dev,
102 struct device_attribute *attr, const char *buf, size_t count)
104 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);
124 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
127 static ssize_t qeth_l3_dev_route6_store(struct device *dev,
128 struct device_attribute *attr, const char *buf, size_t count)
130 struct qeth_card *card = dev_get_drvdata(dev);
135 return qeth_l3_dev_route_store(card, &card->options.route6,
136 QETH_PROT_IPV6, buf, count);
139 static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
140 qeth_l3_dev_route6_store);
142 static ssize_t qeth_l3_dev_fake_broadcast_show(struct device *dev,
143 struct device_attribute *attr, char *buf)
145 struct qeth_card *card = dev_get_drvdata(dev);
150 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
153 static ssize_t qeth_l3_dev_fake_broadcast_store(struct device *dev,
154 struct device_attribute *attr, const char *buf, size_t count)
156 struct qeth_card *card = dev_get_drvdata(dev);
163 if ((card->state != CARD_STATE_DOWN) &&
164 (card->state != CARD_STATE_RECOVER))
167 i = simple_strtoul(buf, &tmp, 16);
168 if ((i == 0) || (i == 1))
169 card->options.fake_broadcast = i;
176 static DEVICE_ATTR(fake_broadcast, 0644, qeth_l3_dev_fake_broadcast_show,
177 qeth_l3_dev_fake_broadcast_store);
179 static ssize_t qeth_l3_dev_broadcast_mode_show(struct device *dev,
180 struct device_attribute *attr, char *buf)
182 struct qeth_card *card = dev_get_drvdata(dev);
187 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
188 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
189 return sprintf(buf, "n/a\n");
191 return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
192 QETH_TR_BROADCAST_ALLRINGS)?
193 "all rings":"local");
196 static ssize_t qeth_l3_dev_broadcast_mode_store(struct device *dev,
197 struct device_attribute *attr, const char *buf, size_t count)
199 struct qeth_card *card = dev_get_drvdata(dev);
205 if ((card->state != CARD_STATE_DOWN) &&
206 (card->state != CARD_STATE_RECOVER))
209 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
210 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))) {
214 tmp = strsep((char **) &buf, "\n");
216 if (!strcmp(tmp, "local")) {
217 card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
219 } else if (!strcmp(tmp, "all_rings")) {
220 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
228 static DEVICE_ATTR(broadcast_mode, 0644, qeth_l3_dev_broadcast_mode_show,
229 qeth_l3_dev_broadcast_mode_store);
231 static ssize_t qeth_l3_dev_canonical_macaddr_show(struct device *dev,
232 struct device_attribute *attr, char *buf)
234 struct qeth_card *card = dev_get_drvdata(dev);
239 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
240 (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
241 return sprintf(buf, "n/a\n");
243 return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
244 QETH_TR_MACADDR_CANONICAL)? 1:0);
247 static ssize_t qeth_l3_dev_canonical_macaddr_store(struct device *dev,
248 struct device_attribute *attr, const char *buf, size_t count)
250 struct qeth_card *card = dev_get_drvdata(dev);
257 if ((card->state != CARD_STATE_DOWN) &&
258 (card->state != CARD_STATE_RECOVER))
261 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
262 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))) {
266 i = simple_strtoul(buf, &tmp, 16);
267 if ((i == 0) || (i == 1))
268 card->options.macaddr_mode = i?
269 QETH_TR_MACADDR_CANONICAL :
270 QETH_TR_MACADDR_NONCANONICAL;
277 static DEVICE_ATTR(canonical_macaddr, 0644, qeth_l3_dev_canonical_macaddr_show,
278 qeth_l3_dev_canonical_macaddr_store);
280 static ssize_t qeth_l3_dev_checksum_show(struct device *dev,
281 struct device_attribute *attr, char *buf)
283 struct qeth_card *card = dev_get_drvdata(dev);
288 return sprintf(buf, "%s checksumming\n",
289 qeth_l3_get_checksum_str(card));
292 static ssize_t qeth_l3_dev_checksum_store(struct device *dev,
293 struct device_attribute *attr, const char *buf, size_t count)
295 struct qeth_card *card = dev_get_drvdata(dev);
301 if ((card->state != CARD_STATE_DOWN) &&
302 (card->state != CARD_STATE_RECOVER))
305 tmp = strsep((char **) &buf, "\n");
306 if (!strcmp(tmp, "sw_checksumming"))
307 card->options.checksum_type = SW_CHECKSUMMING;
308 else if (!strcmp(tmp, "hw_checksumming"))
309 card->options.checksum_type = HW_CHECKSUMMING;
310 else if (!strcmp(tmp, "no_checksumming"))
311 card->options.checksum_type = NO_CHECKSUMMING;
318 static DEVICE_ATTR(checksumming, 0644, qeth_l3_dev_checksum_show,
319 qeth_l3_dev_checksum_store);
321 static struct attribute *qeth_l3_device_attrs[] = {
322 &dev_attr_route4.attr,
323 &dev_attr_route6.attr,
324 &dev_attr_fake_broadcast.attr,
325 &dev_attr_broadcast_mode.attr,
326 &dev_attr_canonical_macaddr.attr,
327 &dev_attr_checksumming.attr,
331 static struct attribute_group qeth_l3_device_attr_group = {
332 .attrs = qeth_l3_device_attrs,
335 static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
336 struct device_attribute *attr, char *buf)
338 struct qeth_card *card = dev_get_drvdata(dev);
343 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
346 static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
347 struct device_attribute *attr, const char *buf, size_t count)
349 struct qeth_card *card = dev_get_drvdata(dev);
355 if ((card->state != CARD_STATE_DOWN) &&
356 (card->state != CARD_STATE_RECOVER))
359 tmp = strsep((char **) &buf, "\n");
360 if (!strcmp(tmp, "toggle")) {
361 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
362 } else if (!strcmp(tmp, "1")) {
363 card->ipato.enabled = 1;
364 } else if (!strcmp(tmp, "0")) {
365 card->ipato.enabled = 0;
372 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
373 qeth_l3_dev_ipato_enable_show,
374 qeth_l3_dev_ipato_enable_store);
376 static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
377 struct device_attribute *attr, char *buf)
379 struct qeth_card *card = dev_get_drvdata(dev);
384 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
387 static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
388 struct device_attribute *attr,
389 const char *buf, size_t count)
391 struct qeth_card *card = dev_get_drvdata(dev);
397 tmp = strsep((char **) &buf, "\n");
398 if (!strcmp(tmp, "toggle")) {
399 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
400 } else if (!strcmp(tmp, "1")) {
401 card->ipato.invert4 = 1;
402 } else if (!strcmp(tmp, "0")) {
403 card->ipato.invert4 = 0;
410 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
411 qeth_l3_dev_ipato_invert4_show,
412 qeth_l3_dev_ipato_invert4_store);
414 static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
415 enum qeth_prot_versions proto)
417 struct qeth_ipato_entry *ipatoe;
420 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
423 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
424 /* add strlen for "/<mask>\n" */
425 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
426 spin_lock_irqsave(&card->ip_lock, flags);
427 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
428 if (ipatoe->proto != proto)
430 /* String must not be longer than PAGE_SIZE. So we check if
431 * string length gets near PAGE_SIZE. Then we can savely display
432 * the next IPv6 address (worst case, compared to IPv4) */
433 if ((PAGE_SIZE - i) <= entry_len)
435 qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
436 i += snprintf(buf + i, PAGE_SIZE - i,
437 "%s/%i\n", addr_str, ipatoe->mask_bits);
439 spin_unlock_irqrestore(&card->ip_lock, flags);
440 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
445 static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
446 struct device_attribute *attr, char *buf)
448 struct qeth_card *card = dev_get_drvdata(dev);
453 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
456 static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
457 u8 *addr, int *mask_bits)
459 const char *start, *end;
461 char buffer[40] = {0, };
464 /* get address string */
465 end = strchr(start, '/');
466 if (!end || (end - start >= 40)) {
469 strncpy(buffer, start, end - start);
470 if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
474 *mask_bits = simple_strtoul(start, &tmp, 10);
475 if (!strlen(start) ||
477 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
483 static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
484 struct qeth_card *card, enum qeth_prot_versions proto)
486 struct qeth_ipato_entry *ipatoe;
491 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
495 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
499 ipatoe->proto = proto;
500 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
501 ipatoe->mask_bits = mask_bits;
503 rc = qeth_l3_add_ipato_entry(card, ipatoe);
512 static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
513 struct device_attribute *attr, const char *buf, size_t count)
515 struct qeth_card *card = dev_get_drvdata(dev);
520 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
523 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
524 qeth_l3_dev_ipato_add4_show,
525 qeth_l3_dev_ipato_add4_store);
527 static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
528 struct qeth_card *card, enum qeth_prot_versions proto)
534 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
538 qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
543 static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
544 struct device_attribute *attr, const char *buf, size_t count)
546 struct qeth_card *card = dev_get_drvdata(dev);
551 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
554 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
555 qeth_l3_dev_ipato_del4_store);
557 static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
558 struct device_attribute *attr, char *buf)
560 struct qeth_card *card = dev_get_drvdata(dev);
565 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
568 static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
569 struct device_attribute *attr, const char *buf, size_t count)
571 struct qeth_card *card = dev_get_drvdata(dev);
577 tmp = strsep((char **) &buf, "\n");
578 if (!strcmp(tmp, "toggle")) {
579 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
580 } else if (!strcmp(tmp, "1")) {
581 card->ipato.invert6 = 1;
582 } else if (!strcmp(tmp, "0")) {
583 card->ipato.invert6 = 0;
590 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
591 qeth_l3_dev_ipato_invert6_show,
592 qeth_l3_dev_ipato_invert6_store);
595 static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
596 struct device_attribute *attr, char *buf)
598 struct qeth_card *card = dev_get_drvdata(dev);
603 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
606 static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
607 struct device_attribute *attr, const char *buf, size_t count)
609 struct qeth_card *card = dev_get_drvdata(dev);
614 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
617 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
618 qeth_l3_dev_ipato_add6_show,
619 qeth_l3_dev_ipato_add6_store);
621 static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
622 struct device_attribute *attr, const char *buf, size_t count)
624 struct qeth_card *card = dev_get_drvdata(dev);
629 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
632 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
633 qeth_l3_dev_ipato_del6_store);
635 static struct attribute *qeth_ipato_device_attrs[] = {
636 &dev_attr_ipato_enable.attr,
637 &dev_attr_ipato_invert4.attr,
638 &dev_attr_ipato_add4.attr,
639 &dev_attr_ipato_del4.attr,
640 &dev_attr_ipato_invert6.attr,
641 &dev_attr_ipato_add6.attr,
642 &dev_attr_ipato_del6.attr,
646 static struct attribute_group qeth_device_ipato_group = {
647 .name = "ipa_takeover",
648 .attrs = qeth_ipato_device_attrs,
651 static ssize_t qeth_l3_dev_vipa_add_show(char *buf, struct qeth_card *card,
652 enum qeth_prot_versions proto)
654 struct qeth_ipaddr *ipaddr;
656 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
660 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
661 entry_len += 2; /* \n + terminator */
662 spin_lock_irqsave(&card->ip_lock, flags);
663 list_for_each_entry(ipaddr, &card->ip_list, entry) {
664 if (ipaddr->proto != proto)
666 if (ipaddr->type != QETH_IP_TYPE_VIPA)
668 /* String must not be longer than PAGE_SIZE. So we check if
669 * string length gets near PAGE_SIZE. Then we can savely display
670 * the next IPv6 address (worst case, compared to IPv4) */
671 if ((PAGE_SIZE - i) <= entry_len)
673 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
675 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
677 spin_unlock_irqrestore(&card->ip_lock, flags);
678 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
683 static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
684 struct device_attribute *attr, char *buf)
686 struct qeth_card *card = dev_get_drvdata(dev);
691 return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
694 static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
697 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
703 static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
704 struct qeth_card *card, enum qeth_prot_versions proto)
709 rc = qeth_l3_parse_vipae(buf, proto, addr);
713 rc = qeth_l3_add_vipa(card, proto, addr);
720 static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
721 struct device_attribute *attr, const char *buf, size_t count)
723 struct qeth_card *card = dev_get_drvdata(dev);
728 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
731 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
732 qeth_l3_dev_vipa_add4_show,
733 qeth_l3_dev_vipa_add4_store);
735 static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
736 struct qeth_card *card, enum qeth_prot_versions proto)
741 rc = qeth_l3_parse_vipae(buf, proto, addr);
745 qeth_l3_del_vipa(card, proto, addr);
750 static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
751 struct device_attribute *attr, const char *buf, size_t count)
753 struct qeth_card *card = dev_get_drvdata(dev);
758 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
761 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
762 qeth_l3_dev_vipa_del4_store);
764 static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
765 struct device_attribute *attr, char *buf)
767 struct qeth_card *card = dev_get_drvdata(dev);
772 return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
775 static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
776 struct device_attribute *attr, const char *buf, size_t count)
778 struct qeth_card *card = dev_get_drvdata(dev);
783 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
786 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
787 qeth_l3_dev_vipa_add6_show,
788 qeth_l3_dev_vipa_add6_store);
790 static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
791 struct device_attribute *attr, const char *buf, size_t count)
793 struct qeth_card *card = dev_get_drvdata(dev);
798 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
801 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
802 qeth_l3_dev_vipa_del6_store);
804 static struct attribute *qeth_vipa_device_attrs[] = {
805 &dev_attr_vipa_add4.attr,
806 &dev_attr_vipa_del4.attr,
807 &dev_attr_vipa_add6.attr,
808 &dev_attr_vipa_del6.attr,
812 static struct attribute_group qeth_device_vipa_group = {
814 .attrs = qeth_vipa_device_attrs,
817 static ssize_t qeth_l3_dev_rxip_add_show(char *buf, struct qeth_card *card,
818 enum qeth_prot_versions proto)
820 struct qeth_ipaddr *ipaddr;
822 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
826 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
827 entry_len += 2; /* \n + terminator */
828 spin_lock_irqsave(&card->ip_lock, flags);
829 list_for_each_entry(ipaddr, &card->ip_list, entry) {
830 if (ipaddr->proto != proto)
832 if (ipaddr->type != QETH_IP_TYPE_RXIP)
834 /* String must not be longer than PAGE_SIZE. So we check if
835 * string length gets near PAGE_SIZE. Then we can savely display
836 * the next IPv6 address (worst case, compared to IPv4) */
837 if ((PAGE_SIZE - i) <= entry_len)
839 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
841 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
843 spin_unlock_irqrestore(&card->ip_lock, flags);
844 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
849 static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
850 struct device_attribute *attr, char *buf)
852 struct qeth_card *card = dev_get_drvdata(dev);
857 return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
860 static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
863 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
869 static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
870 struct qeth_card *card, enum qeth_prot_versions proto)
875 rc = qeth_l3_parse_rxipe(buf, proto, addr);
879 rc = qeth_l3_add_rxip(card, proto, addr);
886 static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
887 struct device_attribute *attr, const char *buf, size_t count)
889 struct qeth_card *card = dev_get_drvdata(dev);
894 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
897 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
898 qeth_l3_dev_rxip_add4_show,
899 qeth_l3_dev_rxip_add4_store);
901 static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
902 struct qeth_card *card, enum qeth_prot_versions proto)
907 rc = qeth_l3_parse_rxipe(buf, proto, addr);
911 qeth_l3_del_rxip(card, proto, addr);
916 static ssize_t qeth_l3_dev_rxip_del4_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_del_store(buf, count, card, QETH_PROT_IPV4);
927 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
928 qeth_l3_dev_rxip_del4_store);
930 static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
931 struct device_attribute *attr, char *buf)
933 struct qeth_card *card = dev_get_drvdata(dev);
938 return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
941 static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
942 struct device_attribute *attr, const char *buf, size_t count)
944 struct qeth_card *card = dev_get_drvdata(dev);
949 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
952 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
953 qeth_l3_dev_rxip_add6_show,
954 qeth_l3_dev_rxip_add6_store);
956 static ssize_t qeth_l3_dev_rxip_del6_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_IPV6);
967 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
968 qeth_l3_dev_rxip_del6_store);
970 static struct attribute *qeth_rxip_device_attrs[] = {
971 &dev_attr_rxip_add4.attr,
972 &dev_attr_rxip_del4.attr,
973 &dev_attr_rxip_add6.attr,
974 &dev_attr_rxip_del6.attr,
978 static struct attribute_group qeth_device_rxip_group = {
980 .attrs = qeth_rxip_device_attrs,
983 int qeth_l3_create_device_attributes(struct device *dev)
987 ret = sysfs_create_group(&dev->kobj, &qeth_l3_device_attr_group);
991 ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group);
993 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
997 ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group);
999 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1000 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1004 ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group);
1006 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1007 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1008 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1014 void qeth_l3_remove_device_attributes(struct device *dev)
1016 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1017 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1018 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1019 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);