media: stv06xx: add missing descriptor sanity checks
[linux/fpc-iii.git] / drivers / s390 / net / qeth_l3_sys.c
blobe8c848f72c6d2ccd3c6c278b6f4fe4d3c18b1b1e
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright IBM Corp. 2007
4 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
8 */
10 #include <linux/slab.h>
11 #include <asm/ebcdic.h>
12 #include <linux/hashtable.h>
13 #include <linux/inet.h>
14 #include "qeth_l3.h"
16 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
17 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
19 static int qeth_l3_string_to_ipaddr(const char *buf,
20 enum qeth_prot_versions proto, u8 *addr)
22 const char *end;
24 if ((proto == QETH_PROT_IPV4 && !in4_pton(buf, -1, addr, -1, &end)) ||
25 (proto == QETH_PROT_IPV6 && !in6_pton(buf, -1, addr, -1, &end)))
26 return -EINVAL;
27 return 0;
30 static ssize_t qeth_l3_dev_route_show(struct qeth_card *card,
31 struct qeth_routing_info *route, char *buf)
33 switch (route->type) {
34 case PRIMARY_ROUTER:
35 return sprintf(buf, "%s\n", "primary router");
36 case SECONDARY_ROUTER:
37 return sprintf(buf, "%s\n", "secondary router");
38 case MULTICAST_ROUTER:
39 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
40 return sprintf(buf, "%s\n", "multicast router+");
41 else
42 return sprintf(buf, "%s\n", "multicast router");
43 case PRIMARY_CONNECTOR:
44 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
45 return sprintf(buf, "%s\n", "primary connector+");
46 else
47 return sprintf(buf, "%s\n", "primary connector");
48 case SECONDARY_CONNECTOR:
49 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
50 return sprintf(buf, "%s\n", "secondary connector+");
51 else
52 return sprintf(buf, "%s\n", "secondary connector");
53 default:
54 return sprintf(buf, "%s\n", "no");
58 static ssize_t qeth_l3_dev_route4_show(struct device *dev,
59 struct device_attribute *attr, char *buf)
61 struct qeth_card *card = dev_get_drvdata(dev);
63 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
66 static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
67 struct qeth_routing_info *route, enum qeth_prot_versions prot,
68 const char *buf, size_t count)
70 enum qeth_routing_types old_route_type = route->type;
71 int rc = 0;
73 mutex_lock(&card->conf_mutex);
74 if (sysfs_streq(buf, "no_router")) {
75 route->type = NO_ROUTER;
76 } else if (sysfs_streq(buf, "primary_connector")) {
77 route->type = PRIMARY_CONNECTOR;
78 } else if (sysfs_streq(buf, "secondary_connector")) {
79 route->type = SECONDARY_CONNECTOR;
80 } else if (sysfs_streq(buf, "primary_router")) {
81 route->type = PRIMARY_ROUTER;
82 } else if (sysfs_streq(buf, "secondary_router")) {
83 route->type = SECONDARY_ROUTER;
84 } else if (sysfs_streq(buf, "multicast_router")) {
85 route->type = MULTICAST_ROUTER;
86 } else {
87 rc = -EINVAL;
88 goto out;
90 if (qeth_card_hw_is_reachable(card) &&
91 (old_route_type != route->type)) {
92 if (prot == QETH_PROT_IPV4)
93 rc = qeth_l3_setrouting_v4(card);
94 else if (prot == QETH_PROT_IPV6)
95 rc = qeth_l3_setrouting_v6(card);
97 out:
98 if (rc)
99 route->type = old_route_type;
100 mutex_unlock(&card->conf_mutex);
101 return rc ? rc : count;
104 static ssize_t qeth_l3_dev_route4_store(struct device *dev,
105 struct device_attribute *attr, const char *buf, size_t count)
107 struct qeth_card *card = dev_get_drvdata(dev);
109 return qeth_l3_dev_route_store(card, &card->options.route4,
110 QETH_PROT_IPV4, buf, count);
113 static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
114 qeth_l3_dev_route4_store);
116 static ssize_t qeth_l3_dev_route6_show(struct device *dev,
117 struct device_attribute *attr, char *buf)
119 struct qeth_card *card = dev_get_drvdata(dev);
121 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
124 static ssize_t qeth_l3_dev_route6_store(struct device *dev,
125 struct device_attribute *attr, const char *buf, size_t count)
127 struct qeth_card *card = dev_get_drvdata(dev);
129 return qeth_l3_dev_route_store(card, &card->options.route6,
130 QETH_PROT_IPV6, buf, count);
133 static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
134 qeth_l3_dev_route6_store);
136 static ssize_t qeth_l3_dev_fake_broadcast_show(struct device *dev,
137 struct device_attribute *attr, char *buf)
139 struct qeth_card *card = dev_get_drvdata(dev);
141 return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
144 static ssize_t qeth_l3_dev_fake_broadcast_store(struct device *dev,
145 struct device_attribute *attr, const char *buf, size_t count)
147 struct qeth_card *card = dev_get_drvdata(dev);
148 char *tmp;
149 int i, rc = 0;
151 mutex_lock(&card->conf_mutex);
152 if (card->state != CARD_STATE_DOWN) {
153 rc = -EPERM;
154 goto out;
157 i = simple_strtoul(buf, &tmp, 16);
158 if ((i == 0) || (i == 1))
159 card->options.fake_broadcast = i;
160 else
161 rc = -EINVAL;
162 out:
163 mutex_unlock(&card->conf_mutex);
164 return rc ? rc : count;
167 static DEVICE_ATTR(fake_broadcast, 0644, qeth_l3_dev_fake_broadcast_show,
168 qeth_l3_dev_fake_broadcast_store);
170 static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
171 struct device_attribute *attr, char *buf)
173 struct qeth_card *card = dev_get_drvdata(dev);
175 return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
178 static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
179 struct device_attribute *attr, const char *buf, size_t count)
181 struct qeth_card *card = dev_get_drvdata(dev);
182 int rc = 0;
183 unsigned long i;
185 if (!IS_IQD(card))
186 return -EPERM;
187 if (card->options.cq == QETH_CQ_ENABLED)
188 return -EPERM;
190 mutex_lock(&card->conf_mutex);
191 if (card->state != CARD_STATE_DOWN) {
192 rc = -EPERM;
193 goto out;
196 rc = kstrtoul(buf, 16, &i);
197 if (rc) {
198 rc = -EINVAL;
199 goto out;
201 switch (i) {
202 case 0:
203 card->options.sniffer = i;
204 break;
205 case 1:
206 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
207 if (card->ssqd.qdioac2 & CHSC_AC2_SNIFFER_AVAILABLE) {
208 card->options.sniffer = i;
209 if (card->qdio.init_pool.buf_count !=
210 QETH_IN_BUF_COUNT_MAX)
211 qeth_realloc_buffer_pool(card,
212 QETH_IN_BUF_COUNT_MAX);
213 } else
214 rc = -EPERM;
215 break;
216 default:
217 rc = -EINVAL;
219 out:
220 mutex_unlock(&card->conf_mutex);
221 return rc ? rc : count;
224 static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
225 qeth_l3_dev_sniffer_store);
227 static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
228 struct device_attribute *attr, char *buf)
230 struct qeth_card *card = dev_get_drvdata(dev);
231 char tmp_hsuid[9];
233 if (!IS_IQD(card))
234 return -EPERM;
236 memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
237 EBCASC(tmp_hsuid, 8);
238 return sprintf(buf, "%s\n", tmp_hsuid);
241 static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
242 struct device_attribute *attr, const char *buf, size_t count)
244 struct qeth_card *card = dev_get_drvdata(dev);
245 int rc = 0;
246 char *tmp;
248 if (!IS_IQD(card))
249 return -EPERM;
251 mutex_lock(&card->conf_mutex);
252 if (card->state != CARD_STATE_DOWN) {
253 rc = -EPERM;
254 goto out;
257 if (card->options.sniffer) {
258 rc = -EPERM;
259 goto out;
262 if (card->options.cq == QETH_CQ_NOTAVAILABLE) {
263 rc = -EPERM;
264 goto out;
267 tmp = strsep((char **)&buf, "\n");
268 if (strlen(tmp) > 8) {
269 rc = -EINVAL;
270 goto out;
273 if (card->options.hsuid[0])
274 /* delete old ip address */
275 qeth_l3_modify_hsuid(card, false);
277 if (strlen(tmp) == 0) {
278 /* delete ip address only */
279 card->options.hsuid[0] = '\0';
280 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
281 qeth_configure_cq(card, QETH_CQ_DISABLED);
282 goto out;
285 if (qeth_configure_cq(card, QETH_CQ_ENABLED)) {
286 rc = -EPERM;
287 goto out;
290 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
291 "%-8s", tmp);
292 ASCEBC(card->options.hsuid, 8);
293 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
295 rc = qeth_l3_modify_hsuid(card, true);
297 out:
298 mutex_unlock(&card->conf_mutex);
299 return rc ? rc : count;
302 static DEVICE_ATTR(hsuid, 0644, qeth_l3_dev_hsuid_show,
303 qeth_l3_dev_hsuid_store);
306 static struct attribute *qeth_l3_device_attrs[] = {
307 &dev_attr_route4.attr,
308 &dev_attr_route6.attr,
309 &dev_attr_fake_broadcast.attr,
310 &dev_attr_sniffer.attr,
311 &dev_attr_hsuid.attr,
312 NULL,
315 static const struct attribute_group qeth_l3_device_attr_group = {
316 .attrs = qeth_l3_device_attrs,
319 static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
320 struct device_attribute *attr, char *buf)
322 struct qeth_card *card = dev_get_drvdata(dev);
324 return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
327 static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
328 struct device_attribute *attr, const char *buf, size_t count)
330 struct qeth_card *card = dev_get_drvdata(dev);
331 bool enable;
332 int rc = 0;
334 mutex_lock(&card->conf_mutex);
335 if (card->state != CARD_STATE_DOWN) {
336 rc = -EPERM;
337 goto out;
340 if (sysfs_streq(buf, "toggle")) {
341 enable = !card->ipato.enabled;
342 } else if (kstrtobool(buf, &enable)) {
343 rc = -EINVAL;
344 goto out;
347 if (card->ipato.enabled != enable) {
348 card->ipato.enabled = enable;
349 mutex_lock(&card->ip_lock);
350 qeth_l3_update_ipato(card);
351 mutex_unlock(&card->ip_lock);
353 out:
354 mutex_unlock(&card->conf_mutex);
355 return rc ? rc : count;
358 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
359 qeth_l3_dev_ipato_enable_show,
360 qeth_l3_dev_ipato_enable_store);
362 static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
363 struct device_attribute *attr, char *buf)
365 struct qeth_card *card = dev_get_drvdata(dev);
367 return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
370 static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
371 struct device_attribute *attr,
372 const char *buf, size_t count)
374 struct qeth_card *card = dev_get_drvdata(dev);
375 bool invert;
376 int rc = 0;
378 mutex_lock(&card->conf_mutex);
379 if (sysfs_streq(buf, "toggle")) {
380 invert = !card->ipato.invert4;
381 } else if (kstrtobool(buf, &invert)) {
382 rc = -EINVAL;
383 goto out;
386 if (card->ipato.invert4 != invert) {
387 card->ipato.invert4 = invert;
388 mutex_lock(&card->ip_lock);
389 qeth_l3_update_ipato(card);
390 mutex_unlock(&card->ip_lock);
392 out:
393 mutex_unlock(&card->conf_mutex);
394 return rc ? rc : count;
397 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
398 qeth_l3_dev_ipato_invert4_show,
399 qeth_l3_dev_ipato_invert4_store);
401 static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
402 enum qeth_prot_versions proto)
404 struct qeth_ipato_entry *ipatoe;
405 char addr_str[40];
406 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
407 int i = 0;
409 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
410 /* add strlen for "/<mask>\n" */
411 entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
412 mutex_lock(&card->ip_lock);
413 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
414 if (ipatoe->proto != proto)
415 continue;
416 /* String must not be longer than PAGE_SIZE. So we check if
417 * string length gets near PAGE_SIZE. Then we can savely display
418 * the next IPv6 address (worst case, compared to IPv4) */
419 if ((PAGE_SIZE - i) <= entry_len)
420 break;
421 qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
422 i += snprintf(buf + i, PAGE_SIZE - i,
423 "%s/%i\n", addr_str, ipatoe->mask_bits);
425 mutex_unlock(&card->ip_lock);
426 i += snprintf(buf + i, PAGE_SIZE - i, "\n");
428 return i;
431 static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
432 struct device_attribute *attr, char *buf)
434 struct qeth_card *card = dev_get_drvdata(dev);
436 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
439 static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
440 u8 *addr, int *mask_bits)
442 const char *start, *end;
443 char *tmp;
444 char buffer[40] = {0, };
446 start = buf;
447 /* get address string */
448 end = strchr(start, '/');
449 if (!end || (end - start >= 40)) {
450 return -EINVAL;
452 strncpy(buffer, start, end - start);
453 if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
454 return -EINVAL;
456 start = end + 1;
457 *mask_bits = simple_strtoul(start, &tmp, 10);
458 if (!strlen(start) ||
459 (tmp == start) ||
460 (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
461 return -EINVAL;
463 return 0;
466 static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
467 struct qeth_card *card, enum qeth_prot_versions proto)
469 struct qeth_ipato_entry *ipatoe;
470 u8 addr[16];
471 int mask_bits;
472 int rc = 0;
474 mutex_lock(&card->conf_mutex);
475 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
476 if (rc)
477 goto out;
479 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
480 if (!ipatoe) {
481 rc = -ENOMEM;
482 goto out;
484 ipatoe->proto = proto;
485 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
486 ipatoe->mask_bits = mask_bits;
488 rc = qeth_l3_add_ipato_entry(card, ipatoe);
489 if (rc)
490 kfree(ipatoe);
491 out:
492 mutex_unlock(&card->conf_mutex);
493 return rc ? rc : count;
496 static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
497 struct device_attribute *attr, const char *buf, size_t count)
499 struct qeth_card *card = dev_get_drvdata(dev);
501 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
504 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
505 qeth_l3_dev_ipato_add4_show,
506 qeth_l3_dev_ipato_add4_store);
508 static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
509 struct qeth_card *card, enum qeth_prot_versions proto)
511 u8 addr[16];
512 int mask_bits;
513 int rc = 0;
515 mutex_lock(&card->conf_mutex);
516 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
517 if (!rc)
518 rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
519 mutex_unlock(&card->conf_mutex);
520 return rc ? rc : count;
523 static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
524 struct device_attribute *attr, const char *buf, size_t count)
526 struct qeth_card *card = dev_get_drvdata(dev);
528 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
531 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
532 qeth_l3_dev_ipato_del4_store);
534 static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
535 struct device_attribute *attr, char *buf)
537 struct qeth_card *card = dev_get_drvdata(dev);
539 return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
542 static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
543 struct device_attribute *attr, const char *buf, size_t count)
545 struct qeth_card *card = dev_get_drvdata(dev);
546 bool invert;
547 int rc = 0;
549 mutex_lock(&card->conf_mutex);
550 if (sysfs_streq(buf, "toggle")) {
551 invert = !card->ipato.invert6;
552 } else if (kstrtobool(buf, &invert)) {
553 rc = -EINVAL;
554 goto out;
557 if (card->ipato.invert6 != invert) {
558 card->ipato.invert6 = invert;
559 mutex_lock(&card->ip_lock);
560 qeth_l3_update_ipato(card);
561 mutex_unlock(&card->ip_lock);
563 out:
564 mutex_unlock(&card->conf_mutex);
565 return rc ? rc : count;
568 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
569 qeth_l3_dev_ipato_invert6_show,
570 qeth_l3_dev_ipato_invert6_store);
573 static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
574 struct device_attribute *attr, char *buf)
576 struct qeth_card *card = dev_get_drvdata(dev);
578 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
581 static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
582 struct device_attribute *attr, const char *buf, size_t count)
584 struct qeth_card *card = dev_get_drvdata(dev);
586 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
589 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
590 qeth_l3_dev_ipato_add6_show,
591 qeth_l3_dev_ipato_add6_store);
593 static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
594 struct device_attribute *attr, const char *buf, size_t count)
596 struct qeth_card *card = dev_get_drvdata(dev);
598 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
601 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
602 qeth_l3_dev_ipato_del6_store);
604 static struct attribute *qeth_ipato_device_attrs[] = {
605 &dev_attr_ipato_enable.attr,
606 &dev_attr_ipato_invert4.attr,
607 &dev_attr_ipato_add4.attr,
608 &dev_attr_ipato_del4.attr,
609 &dev_attr_ipato_invert6.attr,
610 &dev_attr_ipato_add6.attr,
611 &dev_attr_ipato_del6.attr,
612 NULL,
615 static const struct attribute_group qeth_device_ipato_group = {
616 .name = "ipa_takeover",
617 .attrs = qeth_ipato_device_attrs,
620 static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
621 enum qeth_prot_versions proto,
622 enum qeth_ip_types type)
624 struct qeth_card *card = dev_get_drvdata(dev);
625 struct qeth_ipaddr *ipaddr;
626 char addr_str[40];
627 int str_len = 0;
628 int entry_len; /* length of 1 entry string, differs between v4 and v6 */
629 int i;
631 entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
632 entry_len += 2; /* \n + terminator */
633 mutex_lock(&card->ip_lock);
634 hash_for_each(card->ip_htable, i, ipaddr, hnode) {
635 if (ipaddr->proto != proto || ipaddr->type != type)
636 continue;
637 /* String must not be longer than PAGE_SIZE. So we check if
638 * string length gets near PAGE_SIZE. Then we can savely display
639 * the next IPv6 address (worst case, compared to IPv4) */
640 if ((PAGE_SIZE - str_len) <= entry_len)
641 break;
642 qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
643 addr_str);
644 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "%s\n",
645 addr_str);
647 mutex_unlock(&card->ip_lock);
648 str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "\n");
650 return str_len;
653 static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
654 struct device_attribute *attr,
655 char *buf)
657 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
658 QETH_IP_TYPE_VIPA);
661 static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
662 u8 *addr)
664 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
665 return -EINVAL;
667 return 0;
670 static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
671 struct qeth_card *card, enum qeth_prot_versions proto)
673 u8 addr[16] = {0, };
674 int rc;
676 mutex_lock(&card->conf_mutex);
677 rc = qeth_l3_parse_vipae(buf, proto, addr);
678 if (!rc)
679 rc = qeth_l3_modify_rxip_vipa(card, true, addr,
680 QETH_IP_TYPE_VIPA, proto);
681 mutex_unlock(&card->conf_mutex);
682 return rc ? rc : count;
685 static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
686 struct device_attribute *attr, const char *buf, size_t count)
688 struct qeth_card *card = dev_get_drvdata(dev);
690 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
693 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
694 qeth_l3_dev_vipa_add4_show,
695 qeth_l3_dev_vipa_add4_store);
697 static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
698 struct qeth_card *card, enum qeth_prot_versions proto)
700 u8 addr[16];
701 int rc;
703 mutex_lock(&card->conf_mutex);
704 rc = qeth_l3_parse_vipae(buf, proto, addr);
705 if (!rc)
706 rc = qeth_l3_modify_rxip_vipa(card, false, addr,
707 QETH_IP_TYPE_VIPA, proto);
708 mutex_unlock(&card->conf_mutex);
709 return rc ? rc : count;
712 static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
713 struct device_attribute *attr, const char *buf, size_t count)
715 struct qeth_card *card = dev_get_drvdata(dev);
717 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
720 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
721 qeth_l3_dev_vipa_del4_store);
723 static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
724 struct device_attribute *attr,
725 char *buf)
727 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
728 QETH_IP_TYPE_VIPA);
731 static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
732 struct device_attribute *attr, const char *buf, size_t count)
734 struct qeth_card *card = dev_get_drvdata(dev);
736 return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
739 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
740 qeth_l3_dev_vipa_add6_show,
741 qeth_l3_dev_vipa_add6_store);
743 static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
744 struct device_attribute *attr, const char *buf, size_t count)
746 struct qeth_card *card = dev_get_drvdata(dev);
748 return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
751 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
752 qeth_l3_dev_vipa_del6_store);
754 static struct attribute *qeth_vipa_device_attrs[] = {
755 &dev_attr_vipa_add4.attr,
756 &dev_attr_vipa_del4.attr,
757 &dev_attr_vipa_add6.attr,
758 &dev_attr_vipa_del6.attr,
759 NULL,
762 static const struct attribute_group qeth_device_vipa_group = {
763 .name = "vipa",
764 .attrs = qeth_vipa_device_attrs,
767 static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
768 struct device_attribute *attr,
769 char *buf)
771 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
772 QETH_IP_TYPE_RXIP);
775 static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
776 u8 *addr)
778 __be32 ipv4_addr;
779 struct in6_addr ipv6_addr;
781 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
782 return -EINVAL;
784 if (proto == QETH_PROT_IPV4) {
785 memcpy(&ipv4_addr, addr, sizeof(ipv4_addr));
786 if (ipv4_is_multicast(ipv4_addr)) {
787 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
788 return -EINVAL;
790 } else if (proto == QETH_PROT_IPV6) {
791 memcpy(&ipv6_addr, addr, sizeof(ipv6_addr));
792 if (ipv6_addr_is_multicast(&ipv6_addr)) {
793 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
794 return -EINVAL;
798 return 0;
801 static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
802 struct qeth_card *card, enum qeth_prot_versions proto)
804 u8 addr[16] = {0, };
805 int rc;
807 mutex_lock(&card->conf_mutex);
808 rc = qeth_l3_parse_rxipe(buf, proto, addr);
809 if (!rc)
810 rc = qeth_l3_modify_rxip_vipa(card, true, addr,
811 QETH_IP_TYPE_RXIP, proto);
812 mutex_unlock(&card->conf_mutex);
813 return rc ? rc : count;
816 static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
817 struct device_attribute *attr, const char *buf, size_t count)
819 struct qeth_card *card = dev_get_drvdata(dev);
821 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
824 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
825 qeth_l3_dev_rxip_add4_show,
826 qeth_l3_dev_rxip_add4_store);
828 static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
829 struct qeth_card *card, enum qeth_prot_versions proto)
831 u8 addr[16];
832 int rc;
834 mutex_lock(&card->conf_mutex);
835 rc = qeth_l3_parse_rxipe(buf, proto, addr);
836 if (!rc)
837 rc = qeth_l3_modify_rxip_vipa(card, false, addr,
838 QETH_IP_TYPE_RXIP, proto);
839 mutex_unlock(&card->conf_mutex);
840 return rc ? rc : count;
843 static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
844 struct device_attribute *attr, const char *buf, size_t count)
846 struct qeth_card *card = dev_get_drvdata(dev);
848 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
851 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
852 qeth_l3_dev_rxip_del4_store);
854 static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
855 struct device_attribute *attr,
856 char *buf)
858 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
859 QETH_IP_TYPE_RXIP);
862 static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
863 struct device_attribute *attr, const char *buf, size_t count)
865 struct qeth_card *card = dev_get_drvdata(dev);
867 return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
870 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
871 qeth_l3_dev_rxip_add6_show,
872 qeth_l3_dev_rxip_add6_store);
874 static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
875 struct device_attribute *attr, const char *buf, size_t count)
877 struct qeth_card *card = dev_get_drvdata(dev);
879 return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
882 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
883 qeth_l3_dev_rxip_del6_store);
885 static struct attribute *qeth_rxip_device_attrs[] = {
886 &dev_attr_rxip_add4.attr,
887 &dev_attr_rxip_del4.attr,
888 &dev_attr_rxip_add6.attr,
889 &dev_attr_rxip_del6.attr,
890 NULL,
893 static const struct attribute_group qeth_device_rxip_group = {
894 .name = "rxip",
895 .attrs = qeth_rxip_device_attrs,
898 static const struct attribute_group *qeth_l3_only_attr_groups[] = {
899 &qeth_l3_device_attr_group,
900 &qeth_device_ipato_group,
901 &qeth_device_vipa_group,
902 &qeth_device_rxip_group,
903 NULL,
906 int qeth_l3_create_device_attributes(struct device *dev)
908 return sysfs_create_groups(&dev->kobj, qeth_l3_only_attr_groups);
911 void qeth_l3_remove_device_attributes(struct device *dev)
913 sysfs_remove_groups(&dev->kobj, qeth_l3_only_attr_groups);
916 const struct attribute_group *qeth_l3_attr_groups[] = {
917 &qeth_device_attr_group,
918 &qeth_device_blkt_group,
919 /* l3 specific, see qeth_l3_only_attr_groups: */
920 &qeth_l3_device_attr_group,
921 &qeth_device_ipato_group,
922 &qeth_device_vipa_group,
923 &qeth_device_rxip_group,
924 NULL,