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>
11 #include <linux/hashtable.h>
14 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
15 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
17 static ssize_t qeth_l3_dev_route_show(struct qeth_card *card,
18 struct qeth_routing_info *route, char *buf)
20 switch (route->type) {
22 return sprintf(buf, "%s\n", "primary router");
23 case SECONDARY_ROUTER:
24 return sprintf(buf, "%s\n", "secondary router");
25 case MULTICAST_ROUTER:
26 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
27 return sprintf(buf, "%s\n", "multicast router+");
29 return sprintf(buf, "%s\n", "multicast router");
30 case PRIMARY_CONNECTOR:
31 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
32 return sprintf(buf, "%s\n", "primary connector+");
34 return sprintf(buf, "%s\n", "primary connector");
35 case SECONDARY_CONNECTOR:
36 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
37 return sprintf(buf, "%s\n", "secondary connector+");
39 return sprintf(buf, "%s\n", "secondary connector");
41 return sprintf(buf, "%s\n", "no");
45 static ssize_t qeth_l3_dev_route4_show(struct device *dev,
46 struct device_attribute *attr, char *buf)
48 struct qeth_card *card = dev_get_drvdata(dev);
53 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
56 static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
57 struct qeth_routing_info *route, enum qeth_prot_versions prot,
58 const char *buf, size_t count)
60 enum qeth_routing_types old_route_type = route->type;
63 mutex_lock(&card->conf_mutex);
64 if (sysfs_streq(buf, "no_router")) {
65 route->type = NO_ROUTER;
66 } else if (sysfs_streq(buf, "primary_connector")) {
67 route->type = PRIMARY_CONNECTOR;
68 } else if (sysfs_streq(buf, "secondary_connector")) {
69 route->type = SECONDARY_CONNECTOR;
70 } else if (sysfs_streq(buf, "primary_router")) {
71 route->type = PRIMARY_ROUTER;
72 } else if (sysfs_streq(buf, "secondary_router")) {
73 route->type = SECONDARY_ROUTER;
74 } else if (sysfs_streq(buf, "multicast_router")) {
75 route->type = MULTICAST_ROUTER;
80 if (qeth_card_hw_is_reachable(card) &&
81 (old_route_type != route->type)) {
82 if (prot == QETH_PROT_IPV4)
83 rc = qeth_l3_setrouting_v4(card);
84 else if (prot == QETH_PROT_IPV6)
85 rc = qeth_l3_setrouting_v6(card);
89 route->type = old_route_type;
90 mutex_unlock(&card->conf_mutex);
91 return rc ? rc : count;
94 static ssize_t qeth_l3_dev_route4_store(struct device *dev,
95 struct device_attribute *attr, const char *buf, size_t count)
97 struct qeth_card *card = dev_get_drvdata(dev);
102 return qeth_l3_dev_route_store(card, &card->options.route4,
103 QETH_PROT_IPV4, buf, count);
106 static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
107 qeth_l3_dev_route4_store);
109 static ssize_t qeth_l3_dev_route6_show(struct device *dev,
110 struct device_attribute *attr, char *buf)
112 struct qeth_card *card = dev_get_drvdata(dev);
117 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
120 static ssize_t qeth_l3_dev_route6_store(struct device *dev,
121 struct device_attribute *attr, const char *buf, size_t count)
123 struct qeth_card *card = dev_get_drvdata(dev);
128 return qeth_l3_dev_route_store(card, &card->options.route6,
129 QETH_PROT_IPV6, buf, count);
132 static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
133 qeth_l3_dev_route6_store);
135 static ssize_t qeth_l3_dev_fake_broadcast_show(struct device *dev,
136 struct device_attribute *attr, char *buf)
138 struct qeth_card *card = dev_get_drvdata(dev);
143 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
146 static ssize_t qeth_l3_dev_fake_broadcast_store(struct device *dev,
147 struct device_attribute *attr, const char *buf, size_t count)
149 struct qeth_card *card = dev_get_drvdata(dev);
156 mutex_lock(&card->conf_mutex);
157 if ((card->state != CARD_STATE_DOWN) &&
158 (card->state != CARD_STATE_RECOVER)) {
163 i = simple_strtoul(buf, &tmp, 16);
164 if ((i == 0) || (i == 1))
165 card->options.fake_broadcast = i;
169 mutex_unlock(&card->conf_mutex);
170 return rc ? rc : count;
173 static DEVICE_ATTR(fake_broadcast, 0644, qeth_l3_dev_fake_broadcast_show,
174 qeth_l3_dev_fake_broadcast_store);
176 static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
177 struct device_attribute *attr, char *buf)
179 struct qeth_card *card = dev_get_drvdata(dev);
184 return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
187 static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
188 struct device_attribute *attr, const char *buf, size_t count)
190 struct qeth_card *card = dev_get_drvdata(dev);
197 if (card->info.type != QETH_CARD_TYPE_IQD)
199 if (card->options.cq == QETH_CQ_ENABLED)
202 mutex_lock(&card->conf_mutex);
203 if ((card->state != CARD_STATE_DOWN) &&
204 (card->state != CARD_STATE_RECOVER)) {
209 rc = kstrtoul(buf, 16, &i);
216 card->options.sniffer = i;
219 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
220 if (card->ssqd.qdioac2 & QETH_SNIFF_AVAIL) {
221 card->options.sniffer = i;
222 if (card->qdio.init_pool.buf_count !=
223 QETH_IN_BUF_COUNT_MAX)
224 qeth_realloc_buffer_pool(card,
225 QETH_IN_BUF_COUNT_MAX);
233 mutex_unlock(&card->conf_mutex);
234 return rc ? rc : count;
237 static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
238 qeth_l3_dev_sniffer_store);
241 static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
242 struct device_attribute *attr, char *buf)
244 struct qeth_card *card = dev_get_drvdata(dev);
250 if (card->info.type != QETH_CARD_TYPE_IQD)
253 if (card->state == CARD_STATE_DOWN)
256 memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
257 EBCASC(tmp_hsuid, 8);
258 return sprintf(buf, "%s\n", tmp_hsuid);
261 static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
262 struct device_attribute *attr, const char *buf, size_t count)
264 struct qeth_card *card = dev_get_drvdata(dev);
265 struct qeth_ipaddr *addr;
272 if (card->info.type != QETH_CARD_TYPE_IQD)
274 if (card->state != CARD_STATE_DOWN &&
275 card->state != CARD_STATE_RECOVER)
277 if (card->options.sniffer)
279 if (card->options.cq == QETH_CQ_NOTAVAILABLE)
282 tmp = strsep((char **)&buf, "\n");
286 if (card->options.hsuid[0]) {
287 /* delete old ip address */
288 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;
300 spin_lock_bh(&card->ip_lock);
301 qeth_l3_delete_ip(card, addr);
302 spin_unlock_bh(&card->ip_lock);
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 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
320 ASCEBC(card->options.hsuid, 8);
322 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
324 addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
326 addr->u.a6.addr.s6_addr32[0] = 0xfe800000;
327 addr->u.a6.addr.s6_addr32[1] = 0x00000000;
328 for (i = 8; i < 16; i++)
329 addr->u.a6.addr.s6_addr[i] = card->options.hsuid[i - 8];
330 addr->u.a6.pfxlen = 0;
331 addr->type = QETH_IP_TYPE_NORMAL;
335 spin_lock_bh(&card->ip_lock);
336 qeth_l3_add_ip(card, addr);
337 spin_unlock_bh(&card->ip_lock);
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);
381 mutex_lock(&card->conf_mutex);
382 if ((card->state != CARD_STATE_DOWN) &&
383 (card->state != CARD_STATE_RECOVER)) {
388 if (sysfs_streq(buf, "toggle")) {
389 enable = !card->ipato.enabled;
390 } else if (kstrtobool(buf, &enable)) {
395 if (card->ipato.enabled != enable) {
396 card->ipato.enabled = enable;
397 spin_lock_bh(&card->ip_lock);
398 qeth_l3_update_ipato(card);
399 spin_unlock_bh(&card->ip_lock);
402 mutex_unlock(&card->conf_mutex);
403 return rc ? rc : count;
406 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
407 qeth_l3_dev_ipato_enable_show,
408 qeth_l3_dev_ipato_enable_store);
410 static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
411 struct device_attribute *attr, char *buf)
413 struct qeth_card *card = dev_get_drvdata(dev);
418 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
421 static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
422 struct device_attribute *attr,
423 const char *buf, size_t count)
425 struct qeth_card *card = dev_get_drvdata(dev);
432 mutex_lock(&card->conf_mutex);
433 if (sysfs_streq(buf, "toggle")) {
434 invert = !card->ipato.invert4;
435 } else if (kstrtobool(buf, &invert)) {
440 if (card->ipato.invert4 != invert) {
441 card->ipato.invert4 = invert;
442 spin_lock_bh(&card->ip_lock);
443 qeth_l3_update_ipato(card);
444 spin_unlock_bh(&card->ip_lock);
447 mutex_unlock(&card->conf_mutex);
448 return rc ? rc : count;
451 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
452 qeth_l3_dev_ipato_invert4_show,
453 qeth_l3_dev_ipato_invert4_store);
455 static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
456 enum qeth_prot_versions proto)
458 struct qeth_ipato_entry *ipatoe;
460 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
463 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
464 /* add strlen for "/<mask>\n" */
465 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
466 spin_lock_bh(&card->ip_lock);
467 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
468 if (ipatoe->proto != proto)
470 /* String must not be longer than PAGE_SIZE. So we check if
471 * string length gets near PAGE_SIZE. Then we can savely display
472 * the next IPv6 address (worst case, compared to IPv4) */
473 if ((PAGE_SIZE - i) <= entry_len)
475 qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
476 i += snprintf(buf + i, PAGE_SIZE - i,
477 "%s/%i\n", addr_str, ipatoe->mask_bits);
479 spin_unlock_bh(&card->ip_lock);
480 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
485 static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
486 struct device_attribute *attr, char *buf)
488 struct qeth_card *card = dev_get_drvdata(dev);
493 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
496 static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
497 u8 *addr, int *mask_bits)
499 const char *start, *end;
501 char buffer[40] = {0, };
504 /* get address string */
505 end = strchr(start, '/');
506 if (!end || (end - start >= 40)) {
509 strncpy(buffer, start, end - start);
510 if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
514 *mask_bits = simple_strtoul(start, &tmp, 10);
515 if (!strlen(start) ||
517 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
523 static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
524 struct qeth_card *card, enum qeth_prot_versions proto)
526 struct qeth_ipato_entry *ipatoe;
531 mutex_lock(&card->conf_mutex);
532 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
536 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
541 ipatoe->proto = proto;
542 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
543 ipatoe->mask_bits = mask_bits;
545 rc = qeth_l3_add_ipato_entry(card, ipatoe);
549 mutex_unlock(&card->conf_mutex);
550 return rc ? rc : count;
553 static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
554 struct device_attribute *attr, const char *buf, size_t count)
556 struct qeth_card *card = dev_get_drvdata(dev);
561 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
564 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
565 qeth_l3_dev_ipato_add4_show,
566 qeth_l3_dev_ipato_add4_store);
568 static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
569 struct qeth_card *card, enum qeth_prot_versions proto)
575 mutex_lock(&card->conf_mutex);
576 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
578 qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
579 mutex_unlock(&card->conf_mutex);
580 return rc ? rc : count;
583 static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
584 struct device_attribute *attr, const char *buf, size_t count)
586 struct qeth_card *card = dev_get_drvdata(dev);
591 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
594 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
595 qeth_l3_dev_ipato_del4_store);
597 static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
598 struct device_attribute *attr, char *buf)
600 struct qeth_card *card = dev_get_drvdata(dev);
605 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
608 static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
609 struct device_attribute *attr, const char *buf, size_t count)
611 struct qeth_card *card = dev_get_drvdata(dev);
618 mutex_lock(&card->conf_mutex);
619 if (sysfs_streq(buf, "toggle")) {
620 invert = !card->ipato.invert6;
621 } else if (kstrtobool(buf, &invert)) {
626 if (card->ipato.invert6 != invert) {
627 card->ipato.invert6 = invert;
628 spin_lock_bh(&card->ip_lock);
629 qeth_l3_update_ipato(card);
630 spin_unlock_bh(&card->ip_lock);
633 mutex_unlock(&card->conf_mutex);
634 return rc ? rc : count;
637 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
638 qeth_l3_dev_ipato_invert6_show,
639 qeth_l3_dev_ipato_invert6_store);
642 static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
643 struct device_attribute *attr, char *buf)
645 struct qeth_card *card = dev_get_drvdata(dev);
650 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
653 static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
654 struct device_attribute *attr, const char *buf, size_t count)
656 struct qeth_card *card = dev_get_drvdata(dev);
661 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
664 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
665 qeth_l3_dev_ipato_add6_show,
666 qeth_l3_dev_ipato_add6_store);
668 static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
669 struct device_attribute *attr, const char *buf, size_t count)
671 struct qeth_card *card = dev_get_drvdata(dev);
676 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
679 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
680 qeth_l3_dev_ipato_del6_store);
682 static struct attribute *qeth_ipato_device_attrs[] = {
683 &dev_attr_ipato_enable.attr,
684 &dev_attr_ipato_invert4.attr,
685 &dev_attr_ipato_add4.attr,
686 &dev_attr_ipato_del4.attr,
687 &dev_attr_ipato_invert6.attr,
688 &dev_attr_ipato_add6.attr,
689 &dev_attr_ipato_del6.attr,
693 static struct attribute_group qeth_device_ipato_group = {
694 .name = "ipa_takeover",
695 .attrs = qeth_ipato_device_attrs,
698 static ssize_t qeth_l3_dev_vipa_add_show(char *buf, struct qeth_card *card,
699 enum qeth_prot_versions proto)
701 struct qeth_ipaddr *ipaddr;
704 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
707 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
708 entry_len += 2; /* \n + terminator */
709 spin_lock_bh(&card->ip_lock);
710 hash_for_each(card->ip_htable, i, ipaddr, hnode) {
711 if (ipaddr->proto != proto)
713 if (ipaddr->type != QETH_IP_TYPE_VIPA)
715 /* String must not be longer than PAGE_SIZE. So we check if
716 * string length gets near PAGE_SIZE. Then we can savely display
717 * the next IPv6 address (worst case, compared to IPv4) */
718 if ((PAGE_SIZE - str_len) <= entry_len)
720 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
722 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "%s\n",
725 spin_unlock_bh(&card->ip_lock);
726 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "\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;
867 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_bh(&card->ip_lock);
873 hash_for_each(card->ip_htable, i, ipaddr, hnode) {
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 - str_len) <= entry_len)
883 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
885 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "%s\n",
888 spin_unlock_bh(&card->ip_lock);
889 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "\n");
894 static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
895 struct device_attribute *attr, char *buf)
897 struct qeth_card *card = dev_get_drvdata(dev);
902 return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
905 static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
908 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
914 static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
915 struct qeth_card *card, enum qeth_prot_versions proto)
920 mutex_lock(&card->conf_mutex);
921 rc = qeth_l3_parse_rxipe(buf, proto, addr);
923 rc = qeth_l3_add_rxip(card, proto, addr);
924 mutex_unlock(&card->conf_mutex);
925 return rc ? rc : count;
928 static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
929 struct device_attribute *attr, const char *buf, size_t count)
931 struct qeth_card *card = dev_get_drvdata(dev);
936 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
939 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
940 qeth_l3_dev_rxip_add4_show,
941 qeth_l3_dev_rxip_add4_store);
943 static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
944 struct qeth_card *card, enum qeth_prot_versions proto)
949 mutex_lock(&card->conf_mutex);
950 rc = qeth_l3_parse_rxipe(buf, proto, addr);
952 qeth_l3_del_rxip(card, proto, addr);
953 mutex_unlock(&card->conf_mutex);
954 return rc ? rc : count;
957 static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
958 struct device_attribute *attr, const char *buf, size_t count)
960 struct qeth_card *card = dev_get_drvdata(dev);
965 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
968 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
969 qeth_l3_dev_rxip_del4_store);
971 static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
972 struct device_attribute *attr, char *buf)
974 struct qeth_card *card = dev_get_drvdata(dev);
979 return qeth_l3_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
982 static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
983 struct device_attribute *attr, const char *buf, size_t count)
985 struct qeth_card *card = dev_get_drvdata(dev);
990 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
993 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
994 qeth_l3_dev_rxip_add6_show,
995 qeth_l3_dev_rxip_add6_store);
997 static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
998 struct device_attribute *attr, const char *buf, size_t count)
1000 struct qeth_card *card = dev_get_drvdata(dev);
1005 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
1008 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
1009 qeth_l3_dev_rxip_del6_store);
1011 static struct attribute *qeth_rxip_device_attrs[] = {
1012 &dev_attr_rxip_add4.attr,
1013 &dev_attr_rxip_del4.attr,
1014 &dev_attr_rxip_add6.attr,
1015 &dev_attr_rxip_del6.attr,
1019 static struct attribute_group qeth_device_rxip_group = {
1021 .attrs = qeth_rxip_device_attrs,
1024 int qeth_l3_create_device_attributes(struct device *dev)
1028 ret = sysfs_create_group(&dev->kobj, &qeth_l3_device_attr_group);
1032 ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group);
1034 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1038 ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group);
1040 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1041 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1045 ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group);
1047 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1048 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1049 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1055 void qeth_l3_remove_device_attributes(struct device *dev)
1057 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1058 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1059 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
1060 sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);