PM / PCMCIA: Drop second argument of pcmcia_socket_dev_suspend()
[linux-2.6/verdex.git] / drivers / s390 / net / qeth_l3_sys.c
blobc144b9924d52861d57d84e04733a8e11c43bb4d0
1 /*
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>
9 */
11 #include "qeth_l3.h"
13 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
14 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
16 static const char *qeth_l3_get_checksum_str(struct qeth_card *card)
18 if (card->options.checksum_type == SW_CHECKSUMMING)
19 return "sw";
20 else if (card->options.checksum_type == HW_CHECKSUMMING)
21 return "hw";
22 else
23 return "no";
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) {
30 case PRIMARY_ROUTER:
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+");
37 else
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+");
42 else
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+");
47 else
48 return sprintf(buf, "%s\n", "secondary connector");
49 default:
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);
59 if (!card)
60 return -EINVAL;
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;
70 char *tmp;
71 int rc;
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;
87 } else {
88 return -EINVAL;
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);
98 return count;
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);
106 if (!card)
107 return -EINVAL;
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 if (!card)
122 return -EINVAL;
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);
132 if (!card)
133 return -EINVAL;
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);
147 if (!card)
148 return -EINVAL;
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);
157 char *tmp;
158 int i;
160 if (!card)
161 return -EINVAL;
163 if ((card->state != CARD_STATE_DOWN) &&
164 (card->state != CARD_STATE_RECOVER))
165 return -EPERM;
167 i = simple_strtoul(buf, &tmp, 16);
168 if ((i == 0) || (i == 1))
169 card->options.fake_broadcast = i;
170 else {
171 return -EINVAL;
173 return count;
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);
184 if (!card)
185 return -EINVAL;
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);
200 char *tmp;
202 if (!card)
203 return -EINVAL;
205 if ((card->state != CARD_STATE_DOWN) &&
206 (card->state != CARD_STATE_RECOVER))
207 return -EPERM;
209 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
210 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))) {
211 return -EINVAL;
214 tmp = strsep((char **) &buf, "\n");
216 if (!strcmp(tmp, "local")) {
217 card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
218 return count;
219 } else if (!strcmp(tmp, "all_rings")) {
220 card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
221 return count;
222 } else {
223 return -EINVAL;
225 return count;
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);
236 if (!card)
237 return -EINVAL;
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);
251 char *tmp;
252 int i;
254 if (!card)
255 return -EINVAL;
257 if ((card->state != CARD_STATE_DOWN) &&
258 (card->state != CARD_STATE_RECOVER))
259 return -EPERM;
261 if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
262 (card->info.link_type == QETH_LINK_TYPE_LANE_TR))) {
263 return -EINVAL;
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;
271 else {
272 return -EINVAL;
274 return count;
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);
285 if (!card)
286 return -EINVAL;
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 char *tmp;
298 if (!card)
299 return -EINVAL;
301 if ((card->state != CARD_STATE_DOWN) &&
302 (card->state != CARD_STATE_RECOVER))
303 return -EPERM;
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;
312 else {
313 return -EINVAL;
315 return count;
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,
328 NULL,
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);
340 if (!card)
341 return -EINVAL;
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);
350 char *tmp;
352 if (!card)
353 return -EINVAL;
355 if ((card->state != CARD_STATE_DOWN) &&
356 (card->state != CARD_STATE_RECOVER))
357 return -EPERM;
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;
366 } else {
367 return -EINVAL;
369 return count;
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);
381 if (!card)
382 return -EINVAL;
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);
392 char *tmp;
394 if (!card)
395 return -EINVAL;
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;
404 } else {
405 return -EINVAL;
407 return count;
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;
418 unsigned long flags;
419 char addr_str[40];
420 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
421 int i = 0;
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)
429 continue;
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)
434 break;
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");
442 return i;
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);
450 if (!card)
451 return -EINVAL;
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;
460 char *tmp;
461 char buffer[40] = {0, };
463 start = buf;
464 /* get address string */
465 end = strchr(start, '/');
466 if (!end || (end - start >= 40)) {
467 return -EINVAL;
469 strncpy(buffer, start, end - start);
470 if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
471 return -EINVAL;
473 start = end + 1;
474 *mask_bits = simple_strtoul(start, &tmp, 10);
475 if (!strlen(start) ||
476 (tmp == start) ||
477 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
478 return -EINVAL;
480 return 0;
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;
487 u8 addr[16];
488 int mask_bits;
489 int rc;
491 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
492 if (rc)
493 return rc;
495 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
496 if (!ipatoe) {
497 return -ENOMEM;
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);
504 if (rc) {
505 kfree(ipatoe);
506 return rc;
509 return count;
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);
517 if (!card)
518 return -EINVAL;
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)
530 u8 addr[16];
531 int mask_bits;
532 int rc;
534 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
535 if (rc)
536 return rc;
538 qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
540 return count;
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);
548 if (!card)
549 return -EINVAL;
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);
562 if (!card)
563 return -EINVAL;
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);
572 char *tmp;
574 if (!card)
575 return -EINVAL;
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;
584 } else {
585 return -EINVAL;
587 return count;
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);
600 if (!card)
601 return -EINVAL;
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);
611 if (!card)
612 return -EINVAL;
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);
626 if (!card)
627 return -EINVAL;
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,
643 NULL,
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;
655 char addr_str[40];
656 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
657 unsigned long flags;
658 int i = 0;
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)
665 continue;
666 if (ipaddr->type != QETH_IP_TYPE_VIPA)
667 continue;
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)
672 break;
673 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
674 addr_str);
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");
680 return i;
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);
688 if (!card)
689 return -EINVAL;
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,
695 u8 *addr)
697 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
698 return -EINVAL;
700 return 0;
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)
706 u8 addr[16] = {0, };
707 int rc;
709 rc = qeth_l3_parse_vipae(buf, proto, addr);
710 if (rc)
711 return rc;
713 rc = qeth_l3_add_vipa(card, proto, addr);
714 if (rc)
715 return rc;
717 return count;
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);
725 if (!card)
726 return -EINVAL;
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)
738 u8 addr[16];
739 int rc;
741 rc = qeth_l3_parse_vipae(buf, proto, addr);
742 if (rc)
743 return rc;
745 qeth_l3_del_vipa(card, proto, addr);
747 return count;
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);
755 if (!card)
756 return -EINVAL;
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);
769 if (!card)
770 return -EINVAL;
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);
780 if (!card)
781 return -EINVAL;
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);
795 if (!card)
796 return -EINVAL;
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,
809 NULL,
812 static struct attribute_group qeth_device_vipa_group = {
813 .name = "vipa",
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;
821 char addr_str[40];
822 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
823 unsigned long flags;
824 int i = 0;
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)
831 continue;
832 if (ipaddr->type != QETH_IP_TYPE_RXIP)
833 continue;
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)
838 break;
839 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
840 addr_str);
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");
846 return i;
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);
854 if (!card)
855 return -EINVAL;
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,
861 u8 *addr)
863 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
864 return -EINVAL;
866 return 0;
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)
872 u8 addr[16] = {0, };
873 int rc;
875 rc = qeth_l3_parse_rxipe(buf, proto, addr);
876 if (rc)
877 return rc;
879 rc = qeth_l3_add_rxip(card, proto, addr);
880 if (rc)
881 return rc;
883 return count;
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);
891 if (!card)
892 return -EINVAL;
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)
904 u8 addr[16];
905 int rc;
907 rc = qeth_l3_parse_rxipe(buf, proto, addr);
908 if (rc)
909 return rc;
911 qeth_l3_del_rxip(card, proto, addr);
913 return count;
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);
921 if (!card)
922 return -EINVAL;
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);
935 if (!card)
936 return -EINVAL;
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);
946 if (!card)
947 return -EINVAL;
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);
961 if (!card)
962 return -EINVAL;
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,
975 NULL,
978 static struct attribute_group qeth_device_rxip_group = {
979 .name = "rxip",
980 .attrs = qeth_rxip_device_attrs,
983 int qeth_l3_create_device_attributes(struct device *dev)
985 int ret;
987 ret = sysfs_create_group(&dev->kobj, &qeth_l3_device_attr_group);
988 if (ret)
989 return ret;
991 ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group);
992 if (ret) {
993 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
994 return ret;
997 ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group);
998 if (ret) {
999 sysfs_remove_group(&dev->kobj, &qeth_l3_device_attr_group);
1000 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1001 return ret;
1004 ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group);
1005 if (ret) {
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);
1009 return ret;
1011 return 0;
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);