0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/slab.h>
0011 #include <asm/ebcdic.h>
0012 #include <linux/hashtable.h>
0013 #include <linux/inet.h>
0014 #include "qeth_l3.h"
0015
0016 #define QETH_DEVICE_ATTR(_id, _name, _mode, _show, _store) \
0017 struct device_attribute dev_attr_##_id = __ATTR(_name, _mode, _show, _store)
0018
0019 static int qeth_l3_string_to_ipaddr(const char *buf,
0020 enum qeth_prot_versions proto, u8 *addr)
0021 {
0022 const char *end;
0023
0024 if ((proto == QETH_PROT_IPV4 && !in4_pton(buf, -1, addr, -1, &end)) ||
0025 (proto == QETH_PROT_IPV6 && !in6_pton(buf, -1, addr, -1, &end)))
0026 return -EINVAL;
0027 return 0;
0028 }
0029
0030 static ssize_t qeth_l3_dev_route_show(struct qeth_card *card,
0031 struct qeth_routing_info *route, char *buf)
0032 {
0033 switch (route->type) {
0034 case PRIMARY_ROUTER:
0035 return sprintf(buf, "%s\n", "primary router");
0036 case SECONDARY_ROUTER:
0037 return sprintf(buf, "%s\n", "secondary router");
0038 case MULTICAST_ROUTER:
0039 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
0040 return sprintf(buf, "%s\n", "multicast router+");
0041 else
0042 return sprintf(buf, "%s\n", "multicast router");
0043 case PRIMARY_CONNECTOR:
0044 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
0045 return sprintf(buf, "%s\n", "primary connector+");
0046 else
0047 return sprintf(buf, "%s\n", "primary connector");
0048 case SECONDARY_CONNECTOR:
0049 if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
0050 return sprintf(buf, "%s\n", "secondary connector+");
0051 else
0052 return sprintf(buf, "%s\n", "secondary connector");
0053 default:
0054 return sprintf(buf, "%s\n", "no");
0055 }
0056 }
0057
0058 static ssize_t qeth_l3_dev_route4_show(struct device *dev,
0059 struct device_attribute *attr, char *buf)
0060 {
0061 struct qeth_card *card = dev_get_drvdata(dev);
0062
0063 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
0064 }
0065
0066 static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
0067 struct qeth_routing_info *route, enum qeth_prot_versions prot,
0068 const char *buf, size_t count)
0069 {
0070 enum qeth_routing_types old_route_type = route->type;
0071 int rc = 0;
0072
0073 mutex_lock(&card->conf_mutex);
0074 if (sysfs_streq(buf, "no_router")) {
0075 route->type = NO_ROUTER;
0076 } else if (sysfs_streq(buf, "primary_connector")) {
0077 route->type = PRIMARY_CONNECTOR;
0078 } else if (sysfs_streq(buf, "secondary_connector")) {
0079 route->type = SECONDARY_CONNECTOR;
0080 } else if (sysfs_streq(buf, "primary_router")) {
0081 route->type = PRIMARY_ROUTER;
0082 } else if (sysfs_streq(buf, "secondary_router")) {
0083 route->type = SECONDARY_ROUTER;
0084 } else if (sysfs_streq(buf, "multicast_router")) {
0085 route->type = MULTICAST_ROUTER;
0086 } else {
0087 rc = -EINVAL;
0088 goto out;
0089 }
0090 if (qeth_card_hw_is_reachable(card) &&
0091 (old_route_type != route->type)) {
0092 if (prot == QETH_PROT_IPV4)
0093 rc = qeth_l3_setrouting_v4(card);
0094 else if (prot == QETH_PROT_IPV6)
0095 rc = qeth_l3_setrouting_v6(card);
0096 }
0097 out:
0098 if (rc)
0099 route->type = old_route_type;
0100 mutex_unlock(&card->conf_mutex);
0101 return rc ? rc : count;
0102 }
0103
0104 static ssize_t qeth_l3_dev_route4_store(struct device *dev,
0105 struct device_attribute *attr, const char *buf, size_t count)
0106 {
0107 struct qeth_card *card = dev_get_drvdata(dev);
0108
0109 return qeth_l3_dev_route_store(card, &card->options.route4,
0110 QETH_PROT_IPV4, buf, count);
0111 }
0112
0113 static DEVICE_ATTR(route4, 0644, qeth_l3_dev_route4_show,
0114 qeth_l3_dev_route4_store);
0115
0116 static ssize_t qeth_l3_dev_route6_show(struct device *dev,
0117 struct device_attribute *attr, char *buf)
0118 {
0119 struct qeth_card *card = dev_get_drvdata(dev);
0120
0121 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
0122 }
0123
0124 static ssize_t qeth_l3_dev_route6_store(struct device *dev,
0125 struct device_attribute *attr, const char *buf, size_t count)
0126 {
0127 struct qeth_card *card = dev_get_drvdata(dev);
0128
0129 return qeth_l3_dev_route_store(card, &card->options.route6,
0130 QETH_PROT_IPV6, buf, count);
0131 }
0132
0133 static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
0134 qeth_l3_dev_route6_store);
0135
0136 static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
0137 struct device_attribute *attr, char *buf)
0138 {
0139 struct qeth_card *card = dev_get_drvdata(dev);
0140
0141 return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
0142 }
0143
0144 static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
0145 struct device_attribute *attr, const char *buf, size_t count)
0146 {
0147 struct qeth_card *card = dev_get_drvdata(dev);
0148 int rc = 0;
0149 unsigned long i;
0150
0151 if (!IS_IQD(card))
0152 return -EPERM;
0153 if (card->options.cq == QETH_CQ_ENABLED)
0154 return -EPERM;
0155
0156 mutex_lock(&card->conf_mutex);
0157 if (card->state != CARD_STATE_DOWN) {
0158 rc = -EPERM;
0159 goto out;
0160 }
0161
0162 rc = kstrtoul(buf, 16, &i);
0163 if (rc) {
0164 rc = -EINVAL;
0165 goto out;
0166 }
0167 switch (i) {
0168 case 0:
0169 card->options.sniffer = i;
0170 break;
0171 case 1:
0172 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
0173 if (card->ssqd.qdioac2 & CHSC_AC2_SNIFFER_AVAILABLE) {
0174 card->options.sniffer = i;
0175 qeth_resize_buffer_pool(card, QETH_IN_BUF_COUNT_MAX);
0176 } else {
0177 rc = -EPERM;
0178 }
0179
0180 break;
0181 default:
0182 rc = -EINVAL;
0183 }
0184 out:
0185 mutex_unlock(&card->conf_mutex);
0186 return rc ? rc : count;
0187 }
0188
0189 static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
0190 qeth_l3_dev_sniffer_store);
0191
0192 static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
0193 struct device_attribute *attr, char *buf)
0194 {
0195 struct qeth_card *card = dev_get_drvdata(dev);
0196 char tmp_hsuid[9];
0197
0198 if (!IS_IQD(card))
0199 return -EPERM;
0200
0201 memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
0202 EBCASC(tmp_hsuid, 8);
0203 return sprintf(buf, "%s\n", tmp_hsuid);
0204 }
0205
0206 static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
0207 struct device_attribute *attr, const char *buf, size_t count)
0208 {
0209 struct qeth_card *card = dev_get_drvdata(dev);
0210 int rc = 0;
0211 char *tmp;
0212
0213 if (!IS_IQD(card))
0214 return -EPERM;
0215
0216 mutex_lock(&card->conf_mutex);
0217 if (card->state != CARD_STATE_DOWN) {
0218 rc = -EPERM;
0219 goto out;
0220 }
0221
0222 if (card->options.sniffer) {
0223 rc = -EPERM;
0224 goto out;
0225 }
0226
0227 if (card->options.cq == QETH_CQ_NOTAVAILABLE) {
0228 rc = -EPERM;
0229 goto out;
0230 }
0231
0232 tmp = strsep((char **)&buf, "\n");
0233 if (strlen(tmp) > 8) {
0234 rc = -EINVAL;
0235 goto out;
0236 }
0237
0238 if (card->options.hsuid[0])
0239
0240 qeth_l3_modify_hsuid(card, false);
0241
0242 if (strlen(tmp) == 0) {
0243
0244 card->options.hsuid[0] = '\0';
0245 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
0246 qeth_configure_cq(card, QETH_CQ_DISABLED);
0247 goto out;
0248 }
0249
0250 if (qeth_configure_cq(card, QETH_CQ_ENABLED)) {
0251 rc = -EPERM;
0252 goto out;
0253 }
0254
0255 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
0256 "%-8s", tmp);
0257 ASCEBC(card->options.hsuid, 8);
0258 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
0259
0260 rc = qeth_l3_modify_hsuid(card, true);
0261
0262 out:
0263 mutex_unlock(&card->conf_mutex);
0264 return rc ? rc : count;
0265 }
0266
0267 static DEVICE_ATTR(hsuid, 0644, qeth_l3_dev_hsuid_show,
0268 qeth_l3_dev_hsuid_store);
0269
0270
0271 static struct attribute *qeth_l3_device_attrs[] = {
0272 &dev_attr_route4.attr,
0273 &dev_attr_route6.attr,
0274 &dev_attr_sniffer.attr,
0275 &dev_attr_hsuid.attr,
0276 NULL,
0277 };
0278
0279 static const struct attribute_group qeth_l3_device_attr_group = {
0280 .attrs = qeth_l3_device_attrs,
0281 };
0282
0283 static ssize_t qeth_l3_dev_ipato_enable_show(struct device *dev,
0284 struct device_attribute *attr, char *buf)
0285 {
0286 struct qeth_card *card = dev_get_drvdata(dev);
0287
0288 return sprintf(buf, "%u\n", card->ipato.enabled ? 1 : 0);
0289 }
0290
0291 static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
0292 struct device_attribute *attr, const char *buf, size_t count)
0293 {
0294 struct qeth_card *card = dev_get_drvdata(dev);
0295 bool enable;
0296 int rc = 0;
0297
0298 mutex_lock(&card->conf_mutex);
0299 if (card->state != CARD_STATE_DOWN) {
0300 rc = -EPERM;
0301 goto out;
0302 }
0303
0304 mutex_lock(&card->ip_lock);
0305 if (sysfs_streq(buf, "toggle")) {
0306 enable = !card->ipato.enabled;
0307 } else if (kstrtobool(buf, &enable)) {
0308 rc = -EINVAL;
0309 goto unlock_ip;
0310 }
0311
0312 if (card->ipato.enabled != enable) {
0313 card->ipato.enabled = enable;
0314 qeth_l3_update_ipato(card);
0315 }
0316
0317 unlock_ip:
0318 mutex_unlock(&card->ip_lock);
0319 out:
0320 mutex_unlock(&card->conf_mutex);
0321 return rc ? rc : count;
0322 }
0323
0324 static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
0325 qeth_l3_dev_ipato_enable_show,
0326 qeth_l3_dev_ipato_enable_store);
0327
0328 static ssize_t qeth_l3_dev_ipato_invert4_show(struct device *dev,
0329 struct device_attribute *attr, char *buf)
0330 {
0331 struct qeth_card *card = dev_get_drvdata(dev);
0332
0333 return sprintf(buf, "%u\n", card->ipato.invert4 ? 1 : 0);
0334 }
0335
0336 static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
0337 struct device_attribute *attr,
0338 const char *buf, size_t count)
0339 {
0340 struct qeth_card *card = dev_get_drvdata(dev);
0341 bool invert;
0342 int rc = 0;
0343
0344 mutex_lock(&card->ip_lock);
0345 if (sysfs_streq(buf, "toggle")) {
0346 invert = !card->ipato.invert4;
0347 } else if (kstrtobool(buf, &invert)) {
0348 rc = -EINVAL;
0349 goto out;
0350 }
0351
0352 if (card->ipato.invert4 != invert) {
0353 card->ipato.invert4 = invert;
0354 qeth_l3_update_ipato(card);
0355 }
0356
0357 out:
0358 mutex_unlock(&card->ip_lock);
0359 return rc ? rc : count;
0360 }
0361
0362 static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
0363 qeth_l3_dev_ipato_invert4_show,
0364 qeth_l3_dev_ipato_invert4_store);
0365
0366 static ssize_t qeth_l3_dev_ipato_add_show(char *buf, struct qeth_card *card,
0367 enum qeth_prot_versions proto)
0368 {
0369 struct qeth_ipato_entry *ipatoe;
0370 int str_len = 0;
0371
0372 mutex_lock(&card->ip_lock);
0373 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
0374 char addr_str[40];
0375 int entry_len;
0376
0377 if (ipatoe->proto != proto)
0378 continue;
0379
0380 entry_len = qeth_l3_ipaddr_to_string(proto, ipatoe->addr,
0381 addr_str);
0382 if (entry_len < 0)
0383 continue;
0384
0385
0386 entry_len += 1 + ((proto == QETH_PROT_IPV4) ? 2 : 3);
0387
0388 if (entry_len + 1 > PAGE_SIZE - str_len - 1)
0389 break;
0390
0391 entry_len = scnprintf(buf, PAGE_SIZE - str_len,
0392 "%s/%i\n", addr_str, ipatoe->mask_bits);
0393 str_len += entry_len;
0394 buf += entry_len;
0395 }
0396 mutex_unlock(&card->ip_lock);
0397
0398 return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
0399 }
0400
0401 static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
0402 struct device_attribute *attr, char *buf)
0403 {
0404 struct qeth_card *card = dev_get_drvdata(dev);
0405
0406 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
0407 }
0408
0409 static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
0410 u8 *addr, unsigned int *mask_bits)
0411 {
0412 char *sep;
0413 int rc;
0414
0415
0416 sep = strnchr(buf, 40, '/');
0417 if (!sep)
0418 return -EINVAL;
0419
0420
0421 *sep = '\0';
0422 rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
0423 if (rc)
0424 return rc;
0425
0426 rc = kstrtouint(sep + 1, 10, mask_bits);
0427 if (rc)
0428 return rc;
0429
0430 if (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))
0431 return -EINVAL;
0432
0433 return 0;
0434 }
0435
0436 static ssize_t qeth_l3_dev_ipato_add_store(const char *buf, size_t count,
0437 struct qeth_card *card, enum qeth_prot_versions proto)
0438 {
0439 struct qeth_ipato_entry *ipatoe;
0440 unsigned int mask_bits;
0441 u8 addr[16];
0442 int rc = 0;
0443
0444 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
0445 if (rc)
0446 return rc;
0447
0448 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
0449 if (!ipatoe)
0450 return -ENOMEM;
0451
0452 ipatoe->proto = proto;
0453 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4) ? 4 : 16);
0454 ipatoe->mask_bits = mask_bits;
0455
0456 rc = qeth_l3_add_ipato_entry(card, ipatoe);
0457 if (rc)
0458 kfree(ipatoe);
0459
0460 return rc ? rc : count;
0461 }
0462
0463 static ssize_t qeth_l3_dev_ipato_add4_store(struct device *dev,
0464 struct device_attribute *attr, const char *buf, size_t count)
0465 {
0466 struct qeth_card *card = dev_get_drvdata(dev);
0467
0468 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
0469 }
0470
0471 static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
0472 qeth_l3_dev_ipato_add4_show,
0473 qeth_l3_dev_ipato_add4_store);
0474
0475 static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
0476 struct qeth_card *card, enum qeth_prot_versions proto)
0477 {
0478 unsigned int mask_bits;
0479 u8 addr[16];
0480 int rc = 0;
0481
0482 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
0483 if (!rc)
0484 rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
0485 return rc ? rc : count;
0486 }
0487
0488 static ssize_t qeth_l3_dev_ipato_del4_store(struct device *dev,
0489 struct device_attribute *attr, const char *buf, size_t count)
0490 {
0491 struct qeth_card *card = dev_get_drvdata(dev);
0492
0493 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
0494 }
0495
0496 static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
0497 qeth_l3_dev_ipato_del4_store);
0498
0499 static ssize_t qeth_l3_dev_ipato_invert6_show(struct device *dev,
0500 struct device_attribute *attr, char *buf)
0501 {
0502 struct qeth_card *card = dev_get_drvdata(dev);
0503
0504 return sprintf(buf, "%u\n", card->ipato.invert6 ? 1 : 0);
0505 }
0506
0507 static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
0508 struct device_attribute *attr, const char *buf, size_t count)
0509 {
0510 struct qeth_card *card = dev_get_drvdata(dev);
0511 bool invert;
0512 int rc = 0;
0513
0514 mutex_lock(&card->ip_lock);
0515 if (sysfs_streq(buf, "toggle")) {
0516 invert = !card->ipato.invert6;
0517 } else if (kstrtobool(buf, &invert)) {
0518 rc = -EINVAL;
0519 goto out;
0520 }
0521
0522 if (card->ipato.invert6 != invert) {
0523 card->ipato.invert6 = invert;
0524 qeth_l3_update_ipato(card);
0525 }
0526
0527 out:
0528 mutex_unlock(&card->ip_lock);
0529 return rc ? rc : count;
0530 }
0531
0532 static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
0533 qeth_l3_dev_ipato_invert6_show,
0534 qeth_l3_dev_ipato_invert6_store);
0535
0536
0537 static ssize_t qeth_l3_dev_ipato_add6_show(struct device *dev,
0538 struct device_attribute *attr, char *buf)
0539 {
0540 struct qeth_card *card = dev_get_drvdata(dev);
0541
0542 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
0543 }
0544
0545 static ssize_t qeth_l3_dev_ipato_add6_store(struct device *dev,
0546 struct device_attribute *attr, const char *buf, size_t count)
0547 {
0548 struct qeth_card *card = dev_get_drvdata(dev);
0549
0550 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
0551 }
0552
0553 static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
0554 qeth_l3_dev_ipato_add6_show,
0555 qeth_l3_dev_ipato_add6_store);
0556
0557 static ssize_t qeth_l3_dev_ipato_del6_store(struct device *dev,
0558 struct device_attribute *attr, const char *buf, size_t count)
0559 {
0560 struct qeth_card *card = dev_get_drvdata(dev);
0561
0562 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
0563 }
0564
0565 static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
0566 qeth_l3_dev_ipato_del6_store);
0567
0568 static struct attribute *qeth_ipato_device_attrs[] = {
0569 &dev_attr_ipato_enable.attr,
0570 &dev_attr_ipato_invert4.attr,
0571 &dev_attr_ipato_add4.attr,
0572 &dev_attr_ipato_del4.attr,
0573 &dev_attr_ipato_invert6.attr,
0574 &dev_attr_ipato_add6.attr,
0575 &dev_attr_ipato_del6.attr,
0576 NULL,
0577 };
0578
0579 static const struct attribute_group qeth_device_ipato_group = {
0580 .name = "ipa_takeover",
0581 .attrs = qeth_ipato_device_attrs,
0582 };
0583
0584 static ssize_t qeth_l3_dev_ip_add_show(struct device *dev, char *buf,
0585 enum qeth_prot_versions proto,
0586 enum qeth_ip_types type)
0587 {
0588 struct qeth_card *card = dev_get_drvdata(dev);
0589 struct qeth_ipaddr *ipaddr;
0590 int str_len = 0;
0591 int i;
0592
0593 mutex_lock(&card->ip_lock);
0594 hash_for_each(card->ip_htable, i, ipaddr, hnode) {
0595 char addr_str[40];
0596 int entry_len;
0597
0598 if (ipaddr->proto != proto || ipaddr->type != type)
0599 continue;
0600
0601 entry_len = qeth_l3_ipaddr_to_string(proto, (u8 *)&ipaddr->u,
0602 addr_str);
0603 if (entry_len < 0)
0604 continue;
0605
0606
0607 if (entry_len + 1 > PAGE_SIZE - str_len - 1)
0608 break;
0609
0610 entry_len = scnprintf(buf, PAGE_SIZE - str_len, "%s\n",
0611 addr_str);
0612 str_len += entry_len;
0613 buf += entry_len;
0614 }
0615 mutex_unlock(&card->ip_lock);
0616
0617 return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
0618 }
0619
0620 static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
0621 struct device_attribute *attr,
0622 char *buf)
0623 {
0624 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
0625 QETH_IP_TYPE_VIPA);
0626 }
0627
0628 static ssize_t qeth_l3_vipa_store(struct device *dev, const char *buf, bool add,
0629 size_t count, enum qeth_prot_versions proto)
0630 {
0631 struct qeth_card *card = dev_get_drvdata(dev);
0632 u8 addr[16] = {0, };
0633 int rc;
0634
0635 rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
0636 if (!rc)
0637 rc = qeth_l3_modify_rxip_vipa(card, add, addr,
0638 QETH_IP_TYPE_VIPA, proto);
0639 return rc ? rc : count;
0640 }
0641
0642 static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
0643 struct device_attribute *attr, const char *buf, size_t count)
0644 {
0645 return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
0646 }
0647
0648 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
0649 qeth_l3_dev_vipa_add4_show,
0650 qeth_l3_dev_vipa_add4_store);
0651
0652 static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
0653 struct device_attribute *attr, const char *buf, size_t count)
0654 {
0655 return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
0656 }
0657
0658 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
0659 qeth_l3_dev_vipa_del4_store);
0660
0661 static ssize_t qeth_l3_dev_vipa_add6_show(struct device *dev,
0662 struct device_attribute *attr,
0663 char *buf)
0664 {
0665 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
0666 QETH_IP_TYPE_VIPA);
0667 }
0668
0669 static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
0670 struct device_attribute *attr, const char *buf, size_t count)
0671 {
0672 return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV6);
0673 }
0674
0675 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
0676 qeth_l3_dev_vipa_add6_show,
0677 qeth_l3_dev_vipa_add6_store);
0678
0679 static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
0680 struct device_attribute *attr, const char *buf, size_t count)
0681 {
0682 return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV6);
0683 }
0684
0685 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
0686 qeth_l3_dev_vipa_del6_store);
0687
0688 static struct attribute *qeth_vipa_device_attrs[] = {
0689 &dev_attr_vipa_add4.attr,
0690 &dev_attr_vipa_del4.attr,
0691 &dev_attr_vipa_add6.attr,
0692 &dev_attr_vipa_del6.attr,
0693 NULL,
0694 };
0695
0696 static const struct attribute_group qeth_device_vipa_group = {
0697 .name = "vipa",
0698 .attrs = qeth_vipa_device_attrs,
0699 };
0700
0701 static ssize_t qeth_l3_dev_rxip_add4_show(struct device *dev,
0702 struct device_attribute *attr,
0703 char *buf)
0704 {
0705 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV4,
0706 QETH_IP_TYPE_RXIP);
0707 }
0708
0709 static int qeth_l3_parse_rxipe(const char *buf, enum qeth_prot_versions proto,
0710 u8 *addr)
0711 {
0712 __be32 ipv4_addr;
0713 struct in6_addr ipv6_addr;
0714
0715 if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
0716 return -EINVAL;
0717 }
0718 if (proto == QETH_PROT_IPV4) {
0719 memcpy(&ipv4_addr, addr, sizeof(ipv4_addr));
0720 if (ipv4_is_multicast(ipv4_addr)) {
0721 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
0722 return -EINVAL;
0723 }
0724 } else if (proto == QETH_PROT_IPV6) {
0725 memcpy(&ipv6_addr, addr, sizeof(ipv6_addr));
0726 if (ipv6_addr_is_multicast(&ipv6_addr)) {
0727 QETH_DBF_MESSAGE(2, "multicast rxip not supported.\n");
0728 return -EINVAL;
0729 }
0730 }
0731
0732 return 0;
0733 }
0734
0735 static ssize_t qeth_l3_rxip_store(struct device *dev, const char *buf, bool add,
0736 size_t count, enum qeth_prot_versions proto)
0737 {
0738 struct qeth_card *card = dev_get_drvdata(dev);
0739 u8 addr[16] = {0, };
0740 int rc;
0741
0742 rc = qeth_l3_parse_rxipe(buf, proto, addr);
0743 if (!rc)
0744 rc = qeth_l3_modify_rxip_vipa(card, add, addr,
0745 QETH_IP_TYPE_RXIP, proto);
0746 return rc ? rc : count;
0747 }
0748
0749 static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
0750 struct device_attribute *attr, const char *buf, size_t count)
0751 {
0752 return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV4);
0753 }
0754
0755 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
0756 qeth_l3_dev_rxip_add4_show,
0757 qeth_l3_dev_rxip_add4_store);
0758
0759 static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
0760 struct device_attribute *attr, const char *buf, size_t count)
0761 {
0762 return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV4);
0763 }
0764
0765 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
0766 qeth_l3_dev_rxip_del4_store);
0767
0768 static ssize_t qeth_l3_dev_rxip_add6_show(struct device *dev,
0769 struct device_attribute *attr,
0770 char *buf)
0771 {
0772 return qeth_l3_dev_ip_add_show(dev, buf, QETH_PROT_IPV6,
0773 QETH_IP_TYPE_RXIP);
0774 }
0775
0776 static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
0777 struct device_attribute *attr, const char *buf, size_t count)
0778 {
0779 return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV6);
0780 }
0781
0782 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
0783 qeth_l3_dev_rxip_add6_show,
0784 qeth_l3_dev_rxip_add6_store);
0785
0786 static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
0787 struct device_attribute *attr, const char *buf, size_t count)
0788 {
0789 return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV6);
0790 }
0791
0792 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
0793 qeth_l3_dev_rxip_del6_store);
0794
0795 static struct attribute *qeth_rxip_device_attrs[] = {
0796 &dev_attr_rxip_add4.attr,
0797 &dev_attr_rxip_del4.attr,
0798 &dev_attr_rxip_add6.attr,
0799 &dev_attr_rxip_del6.attr,
0800 NULL,
0801 };
0802
0803 static const struct attribute_group qeth_device_rxip_group = {
0804 .name = "rxip",
0805 .attrs = qeth_rxip_device_attrs,
0806 };
0807
0808 const struct attribute_group *qeth_l3_attr_groups[] = {
0809 &qeth_l3_device_attr_group,
0810 &qeth_device_ipato_group,
0811 &qeth_device_vipa_group,
0812 &qeth_device_rxip_group,
0813 NULL,
0814 };