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);
296 enum qeth_checksum_types csum_type;
303 tmp = strsep((char **) &buf, "\n");
304 if (!strcmp(tmp, "sw_checksumming"))
305 csum_type = SW_CHECKSUMMING;
306 else if (!strcmp(tmp, "hw_checksumming"))
307 csum_type = HW_CHECKSUMMING;
308 else if (!strcmp(tmp, "no_checksumming"))
309 csum_type = NO_CHECKSUMMING;
313 rc = qeth_l3_set_rx_csum(card, csum_type);
319 static DEVICE_ATTR(checksumming, 0644, qeth_l3_dev_checksum_show,
320 qeth_l3_dev_checksum_store);
322 static ssize_t qeth_l3_dev_large_send_show(struct device *dev,
323 struct device_attribute *attr, char *buf)
325 struct qeth_card *card = dev_get_drvdata(dev);
330 switch (card->options.large_send) {
331 case QETH_LARGE_SEND_NO:
332 return sprintf(buf, "%s\n", "no");
333 case QETH_LARGE_SEND_TSO:
334 return sprintf(buf, "%s\n", "TSO");
336 return sprintf(buf, "%s\n", "N/A");
340 static ssize_t qeth_l3_dev_large_send_store(struct device *dev,
341 struct device_attribute *attr, const char *buf, size_t count)
343 struct qeth_card *card = dev_get_drvdata(dev);
344 enum qeth_large_send_types type;
350 tmp = strsep((char **) &buf, "\n");
351 if (!strcmp(tmp, "no"))
352 type = QETH_LARGE_SEND_NO;
353 else if (!strcmp(tmp, "TSO"))
354 type = QETH_LARGE_SEND_TSO;
358 if (card->options.large_send == type)
360 rc = qeth_l3_set_large_send(card, type);
366 static DEVICE_ATTR(large_send, 0644, qeth_l3_dev_large_send_show,
367 qeth_l3_dev_large_send_store);
369 static struct attribute *qeth_l3_device_attrs[] = {
370 &dev_attr_route4.attr,
371 &dev_attr_route6.attr,
372 &dev_attr_fake_broadcast.attr,
373 &dev_attr_broadcast_mode.attr,
374 &dev_attr_canonical_macaddr.attr,
375 &dev_attr_checksumming.attr,
376 &dev_attr_large_send.attr,
380 static struct attribute_group qeth_l3_device_attr_group = {
381 .attrs = qeth_l3_device_attrs,
384 static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
385 struct device_attribute *attr, char *buf)
387 struct qeth_card *card = dev_get_drvdata(dev);
392 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
395 static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
396 struct device_attribute *attr, const char *buf, size_t count)
398 struct qeth_card *card = dev_get_drvdata(dev);
404 if ((card->state != CARD_STATE_DOWN) &&
405 (card->state != CARD_STATE_RECOVER))
408 tmp = strsep((char **) &buf, "\n");
409 if (!strcmp(tmp, "toggle")) {
410 card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
411 } else if (!strcmp(tmp, "1")) {
412 card->ipato.enabled = 1;
413 } else if (!strcmp(tmp, "0")) {
414 card->ipato.enabled = 0;
421 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
422 qeth_l3_dev_ipato_enable_show,
423 qeth_l3_dev_ipato_enable_store);
425 static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
426 struct device_attribute *attr, char *buf)
428 struct qeth_card *card = dev_get_drvdata(dev);
433 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
436 static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
437 struct device_attribute *attr,
438 const char *buf, size_t count)
440 struct qeth_card *card = dev_get_drvdata(dev);
446 tmp = strsep((char **) &buf, "\n");
447 if (!strcmp(tmp, "toggle")) {
448 card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
449 } else if (!strcmp(tmp, "1")) {
450 card->ipato.invert4 = 1;
451 } else if (!strcmp(tmp, "0")) {
452 card->ipato.invert4 = 0;
459 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
460 qeth_l3_dev_ipato_invert4_show,
461 qeth_l3_dev_ipato_invert4_store);
463 static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
464 enum qeth_prot_versions proto)
466 struct qeth_ipato_entry *ipatoe;
469 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
472 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
473 /* add strlen for "/<mask>\n" */
474 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
475 spin_lock_irqsave(&card->ip_lock, flags);
476 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
477 if (ipatoe->proto != proto)
479 /* String must not be longer than PAGE_SIZE. So we check if
480 * string length gets near PAGE_SIZE. Then we can savely display
481 * the next IPv6 address (worst case, compared to IPv4) */
482 if ((PAGE_SIZE - i) <= entry_len)
484 qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
485 i += snprintf(buf + i, PAGE_SIZE - i,
486 "%s/%i\n", addr_str, ipatoe->mask_bits);
488 spin_unlock_irqrestore(&card->ip_lock, flags);
489 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
494 static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
495 struct device_attribute *attr, char *buf)
497 struct qeth_card *card = dev_get_drvdata(dev);
502 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
505 static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
506 u8 *addr, int *mask_bits)
508 const char *start, *end;
510 char buffer[40] = {0, };
513 /* get address string */
514 end = strchr(start, '/');
515 if (!end || (end - start >= 40)) {
518 strncpy(buffer, start, end - start);
519 if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
523 *mask_bits = simple_strtoul(start, &tmp, 10);
524 if (!strlen(start) ||
526 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
532 static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
533 struct qeth_card *card, enum qeth_prot_versions proto)
535 struct qeth_ipato_entry *ipatoe;
540 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
544 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
548 ipatoe->proto = proto;
549 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
550 ipatoe->mask_bits = mask_bits;
552 rc = qeth_l3_add_ipato_entry(card, ipatoe);
561 static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
562 struct device_attribute *attr, const char *buf, size_t count)
564 struct qeth_card *card = dev_get_drvdata(dev);
569 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
572 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
573 qeth_l3_dev_ipato_add4_show,
574 qeth_l3_dev_ipato_add4_store);
576 static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
577 struct qeth_card *card, enum qeth_prot_versions proto)
583 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
587 qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
592 static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
593 struct device_attribute *attr, const char *buf, size_t count)
595 struct qeth_card *card = dev_get_drvdata(dev);
600 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
603 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
604 qeth_l3_dev_ipato_del4_store);
606 static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
607 struct device_attribute *attr, char *buf)
609 struct qeth_card *card = dev_get_drvdata(dev);
614 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
617 static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
618 struct device_attribute *attr, const char *buf, size_t count)
620 struct qeth_card *card = dev_get_drvdata(dev);
626 tmp = strsep((char **) &buf, "\n");
627 if (!strcmp(tmp, "toggle")) {
628 card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
629 } else if (!strcmp(tmp, "1")) {
630 card->ipato.invert6 = 1;
631 } else if (!strcmp(tmp, "0")) {
632 card->ipato.invert6 = 0;
639 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
640 qeth_l3_dev_ipato_invert6_show,
641 qeth_l3_dev_ipato_invert6_store);
644 static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
645 struct device_attribute *attr, char *buf)
647 struct qeth_card *card = dev_get_drvdata(dev);
652 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
655 static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
656 struct device_attribute *attr, const char *buf, size_t count)
658 struct qeth_card *card = dev_get_drvdata(dev);
663 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
666 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
667 qeth_l3_dev_ipato_add6_show,
668 qeth_l3_dev_ipato_add6_store);
670 static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
671 struct device_attribute *attr, const char *buf, size_t count)
673 struct qeth_card *card = dev_get_drvdata(dev);
678 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
681 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
682 qeth_l3_dev_ipato_del6_store);
684 static struct attribute *qeth_ipato_device_attrs[] = {
685 &dev_attr_ipato_enable.attr,
686 &dev_attr_ipato_invert4.attr,
687 &dev_attr_ipato_add4.attr,
688 &dev_attr_ipato_del4.attr,
689 &dev_attr_ipato_invert6.attr,
690 &dev_attr_ipato_add6.attr,
691 &dev_attr_ipato_del6.attr,
695 static struct attribute_group qeth_device_ipato_group = {
696 .name = "ipa_takeover",
697 .attrs = qeth_ipato_device_attrs,
700 static ssize_t qeth_l3_dev_vipa_add_show(char *buf, struct qeth_card *card,
701 enum qeth_prot_versions proto)
703 struct qeth_ipaddr *ipaddr;
705 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
709 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
710 entry_len += 2; /* \n + terminator */
711 spin_lock_irqsave(&card->ip_lock, flags);
712 list_for_each_entry(ipaddr, &card->ip_list, entry) {
713 if (ipaddr->proto != proto)
715 if (ipaddr->type != QETH_IP_TYPE_VIPA)
717 /* String must not be longer than PAGE_SIZE. So we check if
718 * string length gets near PAGE_SIZE. Then we can savely display
719 * the next IPv6 address (worst case, compared to IPv4) */
720 if ((PAGE_SIZE - i) <= entry_len)
722 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
724 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
726 spin_unlock_irqrestore(&card->ip_lock, flags);
727 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
732 static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
733 struct device_attribute *attr, char *buf)
735 struct qeth_card *card = dev_get_drvdata(dev);
740 return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
743 static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
746 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
752 static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
753 struct qeth_card *card, enum qeth_prot_versions proto)
758 rc = qeth_l3_parse_vipae(buf, proto, addr);
762 rc = qeth_l3_add_vipa(card, proto, addr);
769 static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
770 struct device_attribute *attr, const char *buf, size_t count)
772 struct qeth_card *card = dev_get_drvdata(dev);
777 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
780 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
781 qeth_l3_dev_vipa_add4_show,
782 qeth_l3_dev_vipa_add4_store);
784 static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
785 struct qeth_card *card, enum qeth_prot_versions proto)
790 rc = qeth_l3_parse_vipae(buf, proto, addr);
794 qeth_l3_del_vipa(card, proto, addr);
799 static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
800 struct device_attribute *attr, const char *buf, size_t count)
802 struct qeth_card *card = dev_get_drvdata(dev);
807 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
810 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
811 qeth_l3_dev_vipa_del4_store);
813 static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
814 struct device_attribute *attr, char *buf)
816 struct qeth_card *card = dev_get_drvdata(dev);
821 return qeth_l3_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
824 static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
825 struct device_attribute *attr, const char *buf, size_t count)
827 struct qeth_card *card = dev_get_drvdata(dev);
832 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
835 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
836 qeth_l3_dev_vipa_add6_show,
837 qeth_l3_dev_vipa_add6_store);
839 static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
840 struct device_attribute *attr, const char *buf, size_t count)
842 struct qeth_card *card = dev_get_drvdata(dev);
847 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
850 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
851 qeth_l3_dev_vipa_del6_store);
853 static struct attribute *qeth_vipa_device_attrs[] = {
854 &dev_attr_vipa_add4.attr,
855 &dev_attr_vipa_del4.attr,
856 &dev_attr_vipa_add6.attr,
857 &dev_attr_vipa_del6.attr,
861 static struct attribute_group qeth_device_vipa_group = {
863 .attrs = qeth_vipa_device_attrs,
866 static ssize_t qeth_l3_dev_rxip_add_show(char *buf, struct qeth_card *card,
867 enum qeth_prot_versions proto)
869 struct qeth_ipaddr *ipaddr;
871 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
875 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
876 entry_len += 2; /* \n + terminator */
877 spin_lock_irqsave(&card->ip_lock, flags);
878 list_for_each_entry(ipaddr, &card->ip_list, entry) {
879 if (ipaddr->proto != proto)
881 if (ipaddr->type != QETH_IP_TYPE_RXIP)
883 /* String must not be longer than PAGE_SIZE. So we check if
884 * string length gets near PAGE_SIZE. Then we can savely display
885 * the next IPv6 address (worst case, compared to IPv4) */
886 if ((PAGE_SIZE - i) <= entry_len)
888 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
890 i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
892 spin_unlock_irqrestore(&card->ip_lock, flags);
893 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
898 static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
899 struct device_attribute *attr, char *buf)
901 struct qeth_card *card = dev_get_drvdata(dev);
906 return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
909 static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
912 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
918 static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
919 struct qeth_card *card, enum qeth_prot_versions proto)
924 rc = qeth_l3_parse_rxipe(buf, proto, addr);
928 rc = qeth_l3_add_rxip(card, proto, addr);
935 static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
936 struct device_attribute *attr, const char *buf, size_t count)
938 struct qeth_card *card = dev_get_drvdata(dev);
943 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
946 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
947 qeth_l3_dev_rxip_add4_show,
948 qeth_l3_dev_rxip_add4_store);
950 static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
951 struct qeth_card *card, enum qeth_prot_versions proto)
956 rc = qeth_l3_parse_rxipe(buf, proto, addr);
960 qeth_l3_del_rxip(card, proto, addr);
965 static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
966 struct device_attribute *attr, const char *buf, size_t count)
968 struct qeth_card *card = dev_get_drvdata(dev);
973 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
976 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
977 qeth_l3_dev_rxip_del4_store);
979 static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
980 struct device_attribute *attr, char *buf)
982 struct qeth_card *card = dev_get_drvdata(dev);
987 return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
990 static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
991 struct device_attribute *attr, const char *buf, size_t count)
993 struct qeth_card *card = dev_get_drvdata(dev);
998 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
1001 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
1002 qeth_l3_dev_rxip_add6_show,
1003 qeth_l3_dev_rxip_add6_store);
1005 static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
1006 struct device_attribute *attr, const char *buf, size_t count)
1008 struct qeth_card *card = dev_get_drvdata(dev);
1013 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
1016 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
1017 qeth_l3_dev_rxip_del6_store);
1019 static struct attribute *qeth_rxip_device_attrs[] = {
1020 &dev_attr_rxip_add4.attr,
1021 &dev_attr_rxip_del4.attr,
1022 &dev_attr_rxip_add6.attr,
1023 &dev_attr_rxip_del6.attr,
1027 static struct attribute_group qeth_device_rxip_group = {
1029 .attrs = qeth_rxip_device_attrs,
1032 int qeth_l3_create_device_attributes(struct device *dev)
1036 ret = sysfs_create_group(&dev->kobj, &qeth_l3_device_attr_group);
1040 ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group);
1042 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1046 ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group);
1048 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1049 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1053 ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group);
1055 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1056 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1057 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1063 void qeth_l3_remove_device_attributes(struct device *dev)
1065 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1066 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1067 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1068 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);