1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright IBM Corp. 2007, 2009 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 */ 9 10 #define KMSG_COMPONENT "qeth" 11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 12 13 #include <linux/module.h> 14 #include <linux/moduleparam.h> 15 #include <linux/bitops.h> 16 #include <linux/string.h> 17 #include <linux/errno.h> 18 #include <linux/kernel.h> 19 #include <linux/etherdevice.h> 20 #include <linux/ip.h> 21 #include <linux/in.h> 22 #include <linux/ipv6.h> 23 #include <linux/inetdevice.h> 24 #include <linux/igmp.h> 25 #include <linux/slab.h> 26 #include <linux/if_ether.h> 27 #include <linux/if_vlan.h> 28 #include <linux/skbuff.h> 29 30 #include <net/ip.h> 31 #include <net/arp.h> 32 #include <net/route.h> 33 #include <net/ipv6.h> 34 #include <net/ip6_route.h> 35 #include <net/ip6_fib.h> 36 #include <net/iucv/af_iucv.h> 37 #include <linux/hashtable.h> 38 39 #include "qeth_l3.h" 40 41 42 static int qeth_l3_set_offline(struct ccwgroup_device *); 43 static void qeth_l3_set_rx_mode(struct net_device *dev); 44 static int qeth_l3_register_addr_entry(struct qeth_card *, 45 struct qeth_ipaddr *); 46 static int qeth_l3_deregister_addr_entry(struct qeth_card *, 47 struct qeth_ipaddr *); 48 49 static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf) 50 { 51 sprintf(buf, "%pI4", addr); 52 } 53 54 static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf) 55 { 56 sprintf(buf, "%pI6", addr); 57 } 58 59 void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr, 60 char *buf) 61 { 62 if (proto == QETH_PROT_IPV4) 63 qeth_l3_ipaddr4_to_string(addr, buf); 64 else if (proto == QETH_PROT_IPV6) 65 qeth_l3_ipaddr6_to_string(addr, buf); 66 } 67 68 static struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions prot) 69 { 70 struct qeth_ipaddr *addr = kmalloc(sizeof(*addr), GFP_ATOMIC); 71 72 if (addr) 73 qeth_l3_init_ipaddr(addr, QETH_IP_TYPE_NORMAL, prot); 74 return addr; 75 } 76 77 static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card, 78 struct qeth_ipaddr *query) 79 { 80 u64 key = qeth_l3_ipaddr_hash(query); 81 struct qeth_ipaddr *addr; 82 83 if (query->is_multicast) { 84 hash_for_each_possible(card->ip_mc_htable, addr, hnode, key) 85 if (qeth_l3_addr_match_ip(addr, query)) 86 return addr; 87 } else { 88 hash_for_each_possible(card->ip_htable, addr, hnode, key) 89 if (qeth_l3_addr_match_ip(addr, query)) 90 return addr; 91 } 92 return NULL; 93 } 94 95 static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len) 96 { 97 int i, j; 98 u8 octet; 99 100 for (i = 0; i < len; ++i) { 101 octet = addr[i]; 102 for (j = 7; j >= 0; --j) { 103 bits[i*8 + j] = octet & 1; 104 octet >>= 1; 105 } 106 } 107 } 108 109 static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card, 110 struct qeth_ipaddr *addr) 111 { 112 struct qeth_ipato_entry *ipatoe; 113 u8 addr_bits[128] = {0, }; 114 u8 ipatoe_bits[128] = {0, }; 115 int rc = 0; 116 117 if (!card->ipato.enabled) 118 return false; 119 if (addr->type != QETH_IP_TYPE_NORMAL) 120 return false; 121 122 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits, 123 (addr->proto == QETH_PROT_IPV4)? 4:16); 124 list_for_each_entry(ipatoe, &card->ipato.entries, entry) { 125 if (addr->proto != ipatoe->proto) 126 continue; 127 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits, 128 (ipatoe->proto == QETH_PROT_IPV4) ? 129 4 : 16); 130 if (addr->proto == QETH_PROT_IPV4) 131 rc = !memcmp(addr_bits, ipatoe_bits, 132 min(32, ipatoe->mask_bits)); 133 else 134 rc = !memcmp(addr_bits, ipatoe_bits, 135 min(128, ipatoe->mask_bits)); 136 if (rc) 137 break; 138 } 139 /* invert? */ 140 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4) 141 rc = !rc; 142 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6) 143 rc = !rc; 144 145 return rc; 146 } 147 148 static int qeth_l3_delete_ip(struct qeth_card *card, 149 struct qeth_ipaddr *tmp_addr) 150 { 151 int rc = 0; 152 struct qeth_ipaddr *addr; 153 154 if (tmp_addr->type == QETH_IP_TYPE_RXIP) 155 QETH_CARD_TEXT(card, 2, "delrxip"); 156 else if (tmp_addr->type == QETH_IP_TYPE_VIPA) 157 QETH_CARD_TEXT(card, 2, "delvipa"); 158 else 159 QETH_CARD_TEXT(card, 2, "delip"); 160 161 if (tmp_addr->proto == QETH_PROT_IPV4) 162 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4); 163 else { 164 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8); 165 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8); 166 } 167 168 addr = qeth_l3_find_addr_by_ip(card, tmp_addr); 169 if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr)) 170 return -ENOENT; 171 172 addr->ref_counter--; 173 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0) 174 return rc; 175 if (addr->in_progress) 176 return -EINPROGRESS; 177 178 if (qeth_card_hw_is_reachable(card)) 179 rc = qeth_l3_deregister_addr_entry(card, addr); 180 181 hash_del(&addr->hnode); 182 kfree(addr); 183 184 return rc; 185 } 186 187 static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr) 188 { 189 int rc = 0; 190 struct qeth_ipaddr *addr; 191 char buf[40]; 192 193 if (tmp_addr->type == QETH_IP_TYPE_RXIP) 194 QETH_CARD_TEXT(card, 2, "addrxip"); 195 else if (tmp_addr->type == QETH_IP_TYPE_VIPA) 196 QETH_CARD_TEXT(card, 2, "addvipa"); 197 else 198 QETH_CARD_TEXT(card, 2, "addip"); 199 200 if (tmp_addr->proto == QETH_PROT_IPV4) 201 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4); 202 else { 203 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8); 204 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8); 205 } 206 207 addr = qeth_l3_find_addr_by_ip(card, tmp_addr); 208 if (addr) { 209 if (tmp_addr->type != QETH_IP_TYPE_NORMAL) 210 return -EADDRINUSE; 211 if (qeth_l3_addr_match_all(addr, tmp_addr)) { 212 addr->ref_counter++; 213 return 0; 214 } 215 qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u, 216 buf); 217 dev_warn(&card->gdev->dev, 218 "Registering IP address %s failed\n", buf); 219 return -EADDRINUSE; 220 } else { 221 addr = qeth_l3_get_addr_buffer(tmp_addr->proto); 222 if (!addr) 223 return -ENOMEM; 224 225 memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr)); 226 addr->ref_counter = 1; 227 228 if (qeth_l3_is_addr_covered_by_ipato(card, addr)) { 229 QETH_CARD_TEXT(card, 2, "tkovaddr"); 230 addr->ipato = 1; 231 } 232 hash_add(card->ip_htable, &addr->hnode, 233 qeth_l3_ipaddr_hash(addr)); 234 235 if (!qeth_card_hw_is_reachable(card)) { 236 addr->disp_flag = QETH_DISP_ADDR_ADD; 237 return 0; 238 } 239 240 /* qeth_l3_register_addr_entry can go to sleep 241 * if we add a IPV4 addr. It is caused by the reason 242 * that SETIP ipa cmd starts ARP staff for IPV4 addr. 243 * Thus we should unlock spinlock, and make a protection 244 * using in_progress variable to indicate that there is 245 * an hardware operation with this IPV4 address 246 */ 247 if (addr->proto == QETH_PROT_IPV4) { 248 addr->in_progress = 1; 249 mutex_unlock(&card->ip_lock); 250 rc = qeth_l3_register_addr_entry(card, addr); 251 mutex_lock(&card->ip_lock); 252 addr->in_progress = 0; 253 } else 254 rc = qeth_l3_register_addr_entry(card, addr); 255 256 if (!rc || rc == -EADDRINUSE || rc == -ENETDOWN) { 257 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 258 if (addr->ref_counter < 1) { 259 qeth_l3_deregister_addr_entry(card, addr); 260 hash_del(&addr->hnode); 261 kfree(addr); 262 } 263 } else { 264 hash_del(&addr->hnode); 265 kfree(addr); 266 } 267 } 268 return rc; 269 } 270 271 static int qeth_l3_modify_ip(struct qeth_card *card, struct qeth_ipaddr *addr, 272 bool add) 273 { 274 int rc; 275 276 mutex_lock(&card->ip_lock); 277 rc = add ? qeth_l3_add_ip(card, addr) : qeth_l3_delete_ip(card, addr); 278 mutex_unlock(&card->ip_lock); 279 280 return rc; 281 } 282 283 static void qeth_l3_drain_rx_mode_cache(struct qeth_card *card) 284 { 285 struct qeth_ipaddr *addr; 286 struct hlist_node *tmp; 287 int i; 288 289 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) { 290 hash_del(&addr->hnode); 291 kfree(addr); 292 } 293 } 294 295 static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover) 296 { 297 struct qeth_ipaddr *addr; 298 struct hlist_node *tmp; 299 int i; 300 301 QETH_CARD_TEXT(card, 4, "clearip"); 302 303 mutex_lock(&card->ip_lock); 304 305 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) { 306 if (!recover) { 307 hash_del(&addr->hnode); 308 kfree(addr); 309 continue; 310 } 311 addr->disp_flag = QETH_DISP_ADDR_ADD; 312 } 313 314 mutex_unlock(&card->ip_lock); 315 } 316 317 static void qeth_l3_recover_ip(struct qeth_card *card) 318 { 319 struct qeth_ipaddr *addr; 320 struct hlist_node *tmp; 321 int i; 322 int rc; 323 324 QETH_CARD_TEXT(card, 4, "recovrip"); 325 326 mutex_lock(&card->ip_lock); 327 328 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) { 329 if (addr->disp_flag == QETH_DISP_ADDR_ADD) { 330 if (addr->proto == QETH_PROT_IPV4) { 331 addr->in_progress = 1; 332 mutex_unlock(&card->ip_lock); 333 rc = qeth_l3_register_addr_entry(card, addr); 334 mutex_lock(&card->ip_lock); 335 addr->in_progress = 0; 336 } else 337 rc = qeth_l3_register_addr_entry(card, addr); 338 339 if (!rc) { 340 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 341 if (addr->ref_counter < 1) 342 qeth_l3_delete_ip(card, addr); 343 } else { 344 hash_del(&addr->hnode); 345 kfree(addr); 346 } 347 } 348 } 349 350 mutex_unlock(&card->ip_lock); 351 } 352 353 static int qeth_l3_setdelip_cb(struct qeth_card *card, struct qeth_reply *reply, 354 unsigned long data) 355 { 356 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 357 358 switch (cmd->hdr.return_code) { 359 case IPA_RC_SUCCESS: 360 return 0; 361 case IPA_RC_DUPLICATE_IP_ADDRESS: 362 return -EADDRINUSE; 363 case IPA_RC_MC_ADDR_NOT_FOUND: 364 return -ENOENT; 365 case IPA_RC_LAN_OFFLINE: 366 return -ENETDOWN; 367 default: 368 return -EIO; 369 } 370 } 371 372 static int qeth_l3_send_setdelmc(struct qeth_card *card, 373 struct qeth_ipaddr *addr, int ipacmd) 374 { 375 struct qeth_cmd_buffer *iob; 376 struct qeth_ipa_cmd *cmd; 377 378 QETH_CARD_TEXT(card, 4, "setdelmc"); 379 380 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto); 381 if (!iob) 382 return -ENOMEM; 383 cmd = __ipa_cmd(iob); 384 ether_addr_copy(cmd->data.setdelipm.mac, addr->mac); 385 if (addr->proto == QETH_PROT_IPV6) 386 memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr, 387 sizeof(struct in6_addr)); 388 else 389 memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4); 390 391 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL); 392 } 393 394 static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len) 395 { 396 int i, j; 397 for (i = 0; i < 16; i++) { 398 j = (len) - (i * 8); 399 if (j >= 8) 400 netmask[i] = 0xff; 401 else if (j > 0) 402 netmask[i] = (u8)(0xFF00 >> j); 403 else 404 netmask[i] = 0; 405 } 406 } 407 408 static u32 qeth_l3_get_setdelip_flags(struct qeth_ipaddr *addr, bool set) 409 { 410 switch (addr->type) { 411 case QETH_IP_TYPE_RXIP: 412 return (set) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0; 413 case QETH_IP_TYPE_VIPA: 414 return (set) ? QETH_IPA_SETIP_VIPA_FLAG : 415 QETH_IPA_DELIP_VIPA_FLAG; 416 default: 417 return (set && addr->ipato) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0; 418 } 419 } 420 421 static int qeth_l3_send_setdelip(struct qeth_card *card, 422 struct qeth_ipaddr *addr, 423 enum qeth_ipa_cmds ipacmd) 424 { 425 struct qeth_cmd_buffer *iob; 426 struct qeth_ipa_cmd *cmd; 427 __u8 netmask[16]; 428 u32 flags; 429 430 QETH_CARD_TEXT(card, 4, "setdelip"); 431 432 iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto); 433 if (!iob) 434 return -ENOMEM; 435 cmd = __ipa_cmd(iob); 436 437 flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP); 438 QETH_CARD_TEXT_(card, 4, "flags%02X", flags); 439 440 if (addr->proto == QETH_PROT_IPV6) { 441 memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr, 442 sizeof(struct in6_addr)); 443 qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen); 444 memcpy(cmd->data.setdelip6.mask, netmask, 445 sizeof(struct in6_addr)); 446 cmd->data.setdelip6.flags = flags; 447 } else { 448 memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4); 449 memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4); 450 cmd->data.setdelip4.flags = flags; 451 } 452 453 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL); 454 } 455 456 static int qeth_l3_send_setrouting(struct qeth_card *card, 457 enum qeth_routing_types type, enum qeth_prot_versions prot) 458 { 459 int rc; 460 struct qeth_ipa_cmd *cmd; 461 struct qeth_cmd_buffer *iob; 462 463 QETH_CARD_TEXT(card, 4, "setroutg"); 464 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot); 465 if (!iob) 466 return -ENOMEM; 467 cmd = __ipa_cmd(iob); 468 cmd->data.setrtg.type = (type); 469 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); 470 471 return rc; 472 } 473 474 static int qeth_l3_correct_routing_type(struct qeth_card *card, 475 enum qeth_routing_types *type, enum qeth_prot_versions prot) 476 { 477 if (IS_IQD(card)) { 478 switch (*type) { 479 case NO_ROUTER: 480 case PRIMARY_CONNECTOR: 481 case SECONDARY_CONNECTOR: 482 case MULTICAST_ROUTER: 483 return 0; 484 default: 485 goto out_inval; 486 } 487 } else { 488 switch (*type) { 489 case NO_ROUTER: 490 case PRIMARY_ROUTER: 491 case SECONDARY_ROUTER: 492 return 0; 493 case MULTICAST_ROUTER: 494 if (qeth_is_ipafunc_supported(card, prot, 495 IPA_OSA_MC_ROUTER)) 496 return 0; 497 default: 498 goto out_inval; 499 } 500 } 501 out_inval: 502 *type = NO_ROUTER; 503 return -EINVAL; 504 } 505 506 int qeth_l3_setrouting_v4(struct qeth_card *card) 507 { 508 int rc; 509 510 QETH_CARD_TEXT(card, 3, "setrtg4"); 511 512 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type, 513 QETH_PROT_IPV4); 514 if (rc) 515 return rc; 516 517 rc = qeth_l3_send_setrouting(card, card->options.route4.type, 518 QETH_PROT_IPV4); 519 if (rc) { 520 card->options.route4.type = NO_ROUTER; 521 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n", 522 rc, CARD_DEVID(card)); 523 } 524 return rc; 525 } 526 527 int qeth_l3_setrouting_v6(struct qeth_card *card) 528 { 529 int rc = 0; 530 531 QETH_CARD_TEXT(card, 3, "setrtg6"); 532 533 if (!qeth_is_supported(card, IPA_IPV6)) 534 return 0; 535 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type, 536 QETH_PROT_IPV6); 537 if (rc) 538 return rc; 539 540 rc = qeth_l3_send_setrouting(card, card->options.route6.type, 541 QETH_PROT_IPV6); 542 if (rc) { 543 card->options.route6.type = NO_ROUTER; 544 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n", 545 rc, CARD_DEVID(card)); 546 } 547 return rc; 548 } 549 550 /* 551 * IP address takeover related functions 552 */ 553 554 /** 555 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs. 556 * 557 * Caller must hold ip_lock. 558 */ 559 void qeth_l3_update_ipato(struct qeth_card *card) 560 { 561 struct qeth_ipaddr *addr; 562 unsigned int i; 563 564 hash_for_each(card->ip_htable, i, addr, hnode) { 565 if (addr->type != QETH_IP_TYPE_NORMAL) 566 continue; 567 addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr); 568 } 569 } 570 571 static void qeth_l3_clear_ipato_list(struct qeth_card *card) 572 { 573 struct qeth_ipato_entry *ipatoe, *tmp; 574 575 mutex_lock(&card->ip_lock); 576 577 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) { 578 list_del(&ipatoe->entry); 579 kfree(ipatoe); 580 } 581 582 qeth_l3_update_ipato(card); 583 mutex_unlock(&card->ip_lock); 584 } 585 586 int qeth_l3_add_ipato_entry(struct qeth_card *card, 587 struct qeth_ipato_entry *new) 588 { 589 struct qeth_ipato_entry *ipatoe; 590 int rc = 0; 591 592 QETH_CARD_TEXT(card, 2, "addipato"); 593 594 mutex_lock(&card->ip_lock); 595 596 list_for_each_entry(ipatoe, &card->ipato.entries, entry) { 597 if (ipatoe->proto != new->proto) 598 continue; 599 if (!memcmp(ipatoe->addr, new->addr, 600 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) && 601 (ipatoe->mask_bits == new->mask_bits)) { 602 rc = -EEXIST; 603 break; 604 } 605 } 606 607 if (!rc) { 608 list_add_tail(&new->entry, &card->ipato.entries); 609 qeth_l3_update_ipato(card); 610 } 611 612 mutex_unlock(&card->ip_lock); 613 614 return rc; 615 } 616 617 int qeth_l3_del_ipato_entry(struct qeth_card *card, 618 enum qeth_prot_versions proto, u8 *addr, 619 int mask_bits) 620 { 621 struct qeth_ipato_entry *ipatoe, *tmp; 622 int rc = -ENOENT; 623 624 QETH_CARD_TEXT(card, 2, "delipato"); 625 626 mutex_lock(&card->ip_lock); 627 628 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) { 629 if (ipatoe->proto != proto) 630 continue; 631 if (!memcmp(ipatoe->addr, addr, 632 (proto == QETH_PROT_IPV4)? 4:16) && 633 (ipatoe->mask_bits == mask_bits)) { 634 list_del(&ipatoe->entry); 635 qeth_l3_update_ipato(card); 636 kfree(ipatoe); 637 rc = 0; 638 } 639 } 640 641 mutex_unlock(&card->ip_lock); 642 return rc; 643 } 644 645 int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip, 646 enum qeth_ip_types type, 647 enum qeth_prot_versions proto) 648 { 649 struct qeth_ipaddr addr; 650 651 qeth_l3_init_ipaddr(&addr, type, proto); 652 if (proto == QETH_PROT_IPV4) 653 memcpy(&addr.u.a4.addr, ip, 4); 654 else 655 memcpy(&addr.u.a6.addr, ip, 16); 656 657 return qeth_l3_modify_ip(card, &addr, add); 658 } 659 660 int qeth_l3_modify_hsuid(struct qeth_card *card, bool add) 661 { 662 struct qeth_ipaddr addr; 663 unsigned int i; 664 665 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6); 666 addr.u.a6.addr.s6_addr[0] = 0xfe; 667 addr.u.a6.addr.s6_addr[1] = 0x80; 668 for (i = 0; i < 8; i++) 669 addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i]; 670 671 return qeth_l3_modify_ip(card, &addr, add); 672 } 673 674 static int qeth_l3_register_addr_entry(struct qeth_card *card, 675 struct qeth_ipaddr *addr) 676 { 677 char buf[50]; 678 int rc = 0; 679 int cnt = 3; 680 681 if (card->options.sniffer) 682 return 0; 683 684 if (addr->proto == QETH_PROT_IPV4) { 685 QETH_CARD_TEXT(card, 2, "setaddr4"); 686 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int)); 687 } else if (addr->proto == QETH_PROT_IPV6) { 688 QETH_CARD_TEXT(card, 2, "setaddr6"); 689 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8); 690 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8); 691 } else { 692 QETH_CARD_TEXT(card, 2, "setaddr?"); 693 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr)); 694 } 695 do { 696 if (addr->is_multicast) 697 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM); 698 else 699 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP); 700 if (rc) 701 QETH_CARD_TEXT(card, 2, "failed"); 702 } while ((--cnt > 0) && rc); 703 if (rc) { 704 QETH_CARD_TEXT(card, 2, "FAILED"); 705 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf); 706 dev_warn(&card->gdev->dev, 707 "Registering IP address %s failed\n", buf); 708 } 709 return rc; 710 } 711 712 static int qeth_l3_deregister_addr_entry(struct qeth_card *card, 713 struct qeth_ipaddr *addr) 714 { 715 int rc = 0; 716 717 if (card->options.sniffer) 718 return 0; 719 720 if (addr->proto == QETH_PROT_IPV4) { 721 QETH_CARD_TEXT(card, 2, "deladdr4"); 722 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int)); 723 } else if (addr->proto == QETH_PROT_IPV6) { 724 QETH_CARD_TEXT(card, 2, "deladdr6"); 725 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8); 726 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8); 727 } else { 728 QETH_CARD_TEXT(card, 2, "deladdr?"); 729 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr)); 730 } 731 if (addr->is_multicast) 732 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM); 733 else 734 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP); 735 if (rc) 736 QETH_CARD_TEXT(card, 2, "failed"); 737 738 return rc; 739 } 740 741 static int qeth_l3_setadapter_parms(struct qeth_card *card) 742 { 743 int rc = 0; 744 745 QETH_DBF_TEXT(SETUP, 2, "setadprm"); 746 747 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) { 748 rc = qeth_setadpparms_change_macaddr(card); 749 if (rc) 750 dev_warn(&card->gdev->dev, "Reading the adapter MAC" 751 " address failed\n"); 752 } 753 754 return rc; 755 } 756 757 static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card) 758 { 759 int rc; 760 761 QETH_CARD_TEXT(card, 3, "ipaarp"); 762 763 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { 764 dev_info(&card->gdev->dev, 765 "ARP processing not supported on %s!\n", 766 QETH_CARD_IFNAME(card)); 767 return 0; 768 } 769 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING, 770 IPA_CMD_ASS_START, 0); 771 if (rc) { 772 dev_warn(&card->gdev->dev, 773 "Starting ARP processing support for %s failed\n", 774 QETH_CARD_IFNAME(card)); 775 } 776 return rc; 777 } 778 779 static int qeth_l3_start_ipa_source_mac(struct qeth_card *card) 780 { 781 int rc; 782 783 QETH_CARD_TEXT(card, 3, "stsrcmac"); 784 785 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) { 786 dev_info(&card->gdev->dev, 787 "Inbound source MAC-address not supported on %s\n", 788 QETH_CARD_IFNAME(card)); 789 return -EOPNOTSUPP; 790 } 791 792 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC, 793 IPA_CMD_ASS_START, 0); 794 if (rc) 795 dev_warn(&card->gdev->dev, 796 "Starting source MAC-address support for %s failed\n", 797 QETH_CARD_IFNAME(card)); 798 return rc; 799 } 800 801 static int qeth_l3_start_ipa_vlan(struct qeth_card *card) 802 { 803 int rc = 0; 804 805 QETH_CARD_TEXT(card, 3, "strtvlan"); 806 807 if (!qeth_is_supported(card, IPA_FULL_VLAN)) { 808 dev_info(&card->gdev->dev, 809 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card)); 810 return -EOPNOTSUPP; 811 } 812 813 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO, 814 IPA_CMD_ASS_START, 0); 815 if (rc) { 816 dev_warn(&card->gdev->dev, 817 "Starting VLAN support for %s failed\n", 818 QETH_CARD_IFNAME(card)); 819 } else { 820 dev_info(&card->gdev->dev, "VLAN enabled\n"); 821 } 822 return rc; 823 } 824 825 static int qeth_l3_start_ipa_multicast(struct qeth_card *card) 826 { 827 int rc; 828 829 QETH_CARD_TEXT(card, 3, "stmcast"); 830 831 if (!qeth_is_supported(card, IPA_MULTICASTING)) { 832 dev_info(&card->gdev->dev, 833 "Multicast not supported on %s\n", 834 QETH_CARD_IFNAME(card)); 835 return -EOPNOTSUPP; 836 } 837 838 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING, 839 IPA_CMD_ASS_START, 0); 840 if (rc) { 841 dev_warn(&card->gdev->dev, 842 "Starting multicast support for %s failed\n", 843 QETH_CARD_IFNAME(card)); 844 } else { 845 dev_info(&card->gdev->dev, "Multicast enabled\n"); 846 card->dev->flags |= IFF_MULTICAST; 847 } 848 return rc; 849 } 850 851 static int qeth_l3_softsetup_ipv6(struct qeth_card *card) 852 { 853 int rc; 854 855 QETH_CARD_TEXT(card, 3, "softipv6"); 856 857 if (IS_IQD(card)) 858 goto out; 859 860 rc = qeth_send_simple_setassparms(card, IPA_IPV6, 861 IPA_CMD_ASS_START, 3); 862 if (rc) { 863 dev_err(&card->gdev->dev, 864 "Activating IPv6 support for %s failed\n", 865 QETH_CARD_IFNAME(card)); 866 return rc; 867 } 868 rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6, 869 IPA_CMD_ASS_START, 0); 870 if (rc) { 871 dev_err(&card->gdev->dev, 872 "Activating IPv6 support for %s failed\n", 873 QETH_CARD_IFNAME(card)); 874 return rc; 875 } 876 rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU, 877 IPA_CMD_ASS_START, 0); 878 if (rc) { 879 dev_warn(&card->gdev->dev, 880 "Enabling the passthrough mode for %s failed\n", 881 QETH_CARD_IFNAME(card)); 882 return rc; 883 } 884 out: 885 dev_info(&card->gdev->dev, "IPV6 enabled\n"); 886 return 0; 887 } 888 889 static int qeth_l3_start_ipa_ipv6(struct qeth_card *card) 890 { 891 QETH_CARD_TEXT(card, 3, "strtipv6"); 892 893 if (!qeth_is_supported(card, IPA_IPV6)) { 894 dev_info(&card->gdev->dev, 895 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card)); 896 return 0; 897 } 898 return qeth_l3_softsetup_ipv6(card); 899 } 900 901 static int qeth_l3_start_ipa_broadcast(struct qeth_card *card) 902 { 903 int rc; 904 905 QETH_CARD_TEXT(card, 3, "stbrdcst"); 906 card->info.broadcast_capable = 0; 907 if (!qeth_is_supported(card, IPA_FILTERING)) { 908 dev_info(&card->gdev->dev, 909 "Broadcast not supported on %s\n", 910 QETH_CARD_IFNAME(card)); 911 rc = -EOPNOTSUPP; 912 goto out; 913 } 914 rc = qeth_send_simple_setassparms(card, IPA_FILTERING, 915 IPA_CMD_ASS_START, 0); 916 if (rc) { 917 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for " 918 "%s failed\n", QETH_CARD_IFNAME(card)); 919 goto out; 920 } 921 922 rc = qeth_send_simple_setassparms(card, IPA_FILTERING, 923 IPA_CMD_ASS_CONFIGURE, 1); 924 if (rc) { 925 dev_warn(&card->gdev->dev, 926 "Setting up broadcast filtering for %s failed\n", 927 QETH_CARD_IFNAME(card)); 928 goto out; 929 } 930 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO; 931 dev_info(&card->gdev->dev, "Broadcast enabled\n"); 932 rc = qeth_send_simple_setassparms(card, IPA_FILTERING, 933 IPA_CMD_ASS_ENABLE, 1); 934 if (rc) { 935 dev_warn(&card->gdev->dev, "Setting up broadcast echo " 936 "filtering for %s failed\n", QETH_CARD_IFNAME(card)); 937 goto out; 938 } 939 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO; 940 out: 941 if (card->info.broadcast_capable) 942 card->dev->flags |= IFF_BROADCAST; 943 else 944 card->dev->flags &= ~IFF_BROADCAST; 945 return rc; 946 } 947 948 static int qeth_l3_start_ipassists(struct qeth_card *card) 949 { 950 QETH_CARD_TEXT(card, 3, "strtipas"); 951 952 if (qeth_set_access_ctrl_online(card, 0)) 953 return -EIO; 954 qeth_l3_start_ipa_arp_processing(card); /* go on*/ 955 qeth_l3_start_ipa_source_mac(card); /* go on*/ 956 qeth_l3_start_ipa_vlan(card); /* go on*/ 957 qeth_l3_start_ipa_multicast(card); /* go on*/ 958 qeth_l3_start_ipa_ipv6(card); /* go on*/ 959 qeth_l3_start_ipa_broadcast(card); /* go on*/ 960 return 0; 961 } 962 963 static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card, 964 struct qeth_reply *reply, unsigned long data) 965 { 966 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 967 968 if (cmd->hdr.return_code) 969 return -EIO; 970 971 ether_addr_copy(card->dev->dev_addr, 972 cmd->data.create_destroy_addr.unique_id); 973 return 0; 974 } 975 976 static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card) 977 { 978 int rc = 0; 979 struct qeth_cmd_buffer *iob; 980 struct qeth_ipa_cmd *cmd; 981 982 QETH_DBF_TEXT(SETUP, 2, "hsrmac"); 983 984 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR, 985 QETH_PROT_IPV6); 986 if (!iob) 987 return -ENOMEM; 988 cmd = __ipa_cmd(iob); 989 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = 990 card->info.unique_id; 991 992 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb, 993 NULL); 994 return rc; 995 } 996 997 static int qeth_l3_get_unique_id_cb(struct qeth_card *card, 998 struct qeth_reply *reply, unsigned long data) 999 { 1000 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1001 1002 if (cmd->hdr.return_code == 0) { 1003 card->info.unique_id = *((__u16 *) 1004 &cmd->data.create_destroy_addr.unique_id[6]); 1005 return 0; 1006 } 1007 1008 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | 1009 UNIQUE_ID_NOT_BY_CARD; 1010 dev_warn(&card->gdev->dev, "The network adapter failed to generate a unique ID\n"); 1011 return -EIO; 1012 } 1013 1014 static int qeth_l3_get_unique_id(struct qeth_card *card) 1015 { 1016 int rc = 0; 1017 struct qeth_cmd_buffer *iob; 1018 struct qeth_ipa_cmd *cmd; 1019 1020 QETH_DBF_TEXT(SETUP, 2, "guniqeid"); 1021 1022 if (!qeth_is_supported(card, IPA_IPV6)) { 1023 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | 1024 UNIQUE_ID_NOT_BY_CARD; 1025 return 0; 1026 } 1027 1028 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR, 1029 QETH_PROT_IPV6); 1030 if (!iob) 1031 return -ENOMEM; 1032 cmd = __ipa_cmd(iob); 1033 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = 1034 card->info.unique_id; 1035 1036 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL); 1037 return rc; 1038 } 1039 1040 static int 1041 qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply, 1042 unsigned long data) 1043 { 1044 struct qeth_ipa_cmd *cmd; 1045 __u16 rc; 1046 1047 QETH_DBF_TEXT(SETUP, 2, "diastrcb"); 1048 1049 cmd = (struct qeth_ipa_cmd *)data; 1050 rc = cmd->hdr.return_code; 1051 if (rc) 1052 QETH_CARD_TEXT_(card, 2, "dxter%x", rc); 1053 switch (cmd->data.diagass.action) { 1054 case QETH_DIAGS_CMD_TRACE_QUERY: 1055 break; 1056 case QETH_DIAGS_CMD_TRACE_DISABLE: 1057 switch (rc) { 1058 case 0: 1059 case IPA_RC_INVALID_SUBCMD: 1060 card->info.promisc_mode = SET_PROMISC_MODE_OFF; 1061 dev_info(&card->gdev->dev, "The HiperSockets network " 1062 "traffic analyzer is deactivated\n"); 1063 break; 1064 default: 1065 break; 1066 } 1067 break; 1068 case QETH_DIAGS_CMD_TRACE_ENABLE: 1069 switch (rc) { 1070 case 0: 1071 card->info.promisc_mode = SET_PROMISC_MODE_ON; 1072 dev_info(&card->gdev->dev, "The HiperSockets network " 1073 "traffic analyzer is activated\n"); 1074 break; 1075 case IPA_RC_HARDWARE_AUTH_ERROR: 1076 dev_warn(&card->gdev->dev, "The device is not " 1077 "authorized to run as a HiperSockets network " 1078 "traffic analyzer\n"); 1079 break; 1080 case IPA_RC_TRACE_ALREADY_ACTIVE: 1081 dev_warn(&card->gdev->dev, "A HiperSockets " 1082 "network traffic analyzer is already " 1083 "active in the HiperSockets LAN\n"); 1084 break; 1085 default: 1086 break; 1087 } 1088 break; 1089 default: 1090 QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n", 1091 cmd->data.diagass.action, CARD_DEVID(card)); 1092 } 1093 1094 return rc ? -EIO : 0; 1095 } 1096 1097 static int 1098 qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd) 1099 { 1100 struct qeth_cmd_buffer *iob; 1101 struct qeth_ipa_cmd *cmd; 1102 1103 QETH_DBF_TEXT(SETUP, 2, "diagtrac"); 1104 1105 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0); 1106 if (!iob) 1107 return -ENOMEM; 1108 cmd = __ipa_cmd(iob); 1109 cmd->data.diagass.subcmd_len = 16; 1110 cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE; 1111 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET; 1112 cmd->data.diagass.action = diags_cmd; 1113 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL); 1114 } 1115 1116 static void 1117 qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev) 1118 { 1119 struct ip_mc_list *im4; 1120 struct qeth_ipaddr *tmp, *ipm; 1121 1122 QETH_CARD_TEXT(card, 4, "addmc"); 1123 1124 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4); 1125 if (!tmp) 1126 return; 1127 1128 for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL; 1129 im4 = rcu_dereference(im4->next_rcu)) { 1130 ip_eth_mc_map(im4->multiaddr, tmp->mac); 1131 tmp->u.a4.addr = be32_to_cpu(im4->multiaddr); 1132 tmp->is_multicast = 1; 1133 1134 ipm = qeth_l3_find_addr_by_ip(card, tmp); 1135 if (ipm) { 1136 /* for mcast, by-IP match means full match */ 1137 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 1138 } else { 1139 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4); 1140 if (!ipm) 1141 continue; 1142 ether_addr_copy(ipm->mac, tmp->mac); 1143 ipm->u.a4.addr = be32_to_cpu(im4->multiaddr); 1144 ipm->is_multicast = 1; 1145 ipm->disp_flag = QETH_DISP_ADDR_ADD; 1146 hash_add(card->ip_mc_htable, 1147 &ipm->hnode, qeth_l3_ipaddr_hash(ipm)); 1148 } 1149 } 1150 1151 kfree(tmp); 1152 } 1153 1154 /* called with rcu_read_lock */ 1155 static void qeth_l3_add_vlan_mc(struct qeth_card *card) 1156 { 1157 struct in_device *in_dev; 1158 u16 vid; 1159 1160 QETH_CARD_TEXT(card, 4, "addmcvl"); 1161 1162 if (!qeth_is_supported(card, IPA_FULL_VLAN)) 1163 return; 1164 1165 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) { 1166 struct net_device *netdev; 1167 1168 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), 1169 vid); 1170 if (netdev == NULL || 1171 !(netdev->flags & IFF_UP)) 1172 continue; 1173 in_dev = __in_dev_get_rcu(netdev); 1174 if (!in_dev) 1175 continue; 1176 qeth_l3_add_mc_to_hash(card, in_dev); 1177 } 1178 } 1179 1180 static void qeth_l3_add_multicast_ipv4(struct qeth_card *card) 1181 { 1182 struct in_device *in4_dev; 1183 1184 QETH_CARD_TEXT(card, 4, "chkmcv4"); 1185 1186 rcu_read_lock(); 1187 in4_dev = __in_dev_get_rcu(card->dev); 1188 if (in4_dev == NULL) 1189 goto unlock; 1190 qeth_l3_add_mc_to_hash(card, in4_dev); 1191 qeth_l3_add_vlan_mc(card); 1192 unlock: 1193 rcu_read_unlock(); 1194 } 1195 1196 static void qeth_l3_add_mc6_to_hash(struct qeth_card *card, 1197 struct inet6_dev *in6_dev) 1198 { 1199 struct qeth_ipaddr *ipm; 1200 struct ifmcaddr6 *im6; 1201 struct qeth_ipaddr *tmp; 1202 1203 QETH_CARD_TEXT(card, 4, "addmc6"); 1204 1205 tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6); 1206 if (!tmp) 1207 return; 1208 1209 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) { 1210 ipv6_eth_mc_map(&im6->mca_addr, tmp->mac); 1211 memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr, 1212 sizeof(struct in6_addr)); 1213 tmp->is_multicast = 1; 1214 1215 ipm = qeth_l3_find_addr_by_ip(card, tmp); 1216 if (ipm) { 1217 /* for mcast, by-IP match means full match */ 1218 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 1219 continue; 1220 } 1221 1222 ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6); 1223 if (!ipm) 1224 continue; 1225 1226 ether_addr_copy(ipm->mac, tmp->mac); 1227 memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr, 1228 sizeof(struct in6_addr)); 1229 ipm->is_multicast = 1; 1230 ipm->disp_flag = QETH_DISP_ADDR_ADD; 1231 hash_add(card->ip_mc_htable, 1232 &ipm->hnode, qeth_l3_ipaddr_hash(ipm)); 1233 1234 } 1235 kfree(tmp); 1236 } 1237 1238 /* called with rcu_read_lock */ 1239 static void qeth_l3_add_vlan_mc6(struct qeth_card *card) 1240 { 1241 struct inet6_dev *in_dev; 1242 u16 vid; 1243 1244 QETH_CARD_TEXT(card, 4, "admc6vl"); 1245 1246 if (!qeth_is_supported(card, IPA_FULL_VLAN)) 1247 return; 1248 1249 for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) { 1250 struct net_device *netdev; 1251 1252 netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), 1253 vid); 1254 if (netdev == NULL || 1255 !(netdev->flags & IFF_UP)) 1256 continue; 1257 in_dev = in6_dev_get(netdev); 1258 if (!in_dev) 1259 continue; 1260 read_lock_bh(&in_dev->lock); 1261 qeth_l3_add_mc6_to_hash(card, in_dev); 1262 read_unlock_bh(&in_dev->lock); 1263 in6_dev_put(in_dev); 1264 } 1265 } 1266 1267 static void qeth_l3_add_multicast_ipv6(struct qeth_card *card) 1268 { 1269 struct inet6_dev *in6_dev; 1270 1271 QETH_CARD_TEXT(card, 4, "chkmcv6"); 1272 1273 if (!qeth_is_supported(card, IPA_IPV6)) 1274 return ; 1275 in6_dev = in6_dev_get(card->dev); 1276 if (!in6_dev) 1277 return; 1278 1279 rcu_read_lock(); 1280 read_lock_bh(&in6_dev->lock); 1281 qeth_l3_add_mc6_to_hash(card, in6_dev); 1282 qeth_l3_add_vlan_mc6(card); 1283 read_unlock_bh(&in6_dev->lock); 1284 rcu_read_unlock(); 1285 in6_dev_put(in6_dev); 1286 } 1287 1288 static int qeth_l3_vlan_rx_add_vid(struct net_device *dev, 1289 __be16 proto, u16 vid) 1290 { 1291 struct qeth_card *card = dev->ml_priv; 1292 1293 set_bit(vid, card->active_vlans); 1294 return 0; 1295 } 1296 1297 static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev, 1298 __be16 proto, u16 vid) 1299 { 1300 struct qeth_card *card = dev->ml_priv; 1301 1302 QETH_CARD_TEXT_(card, 4, "kid:%d", vid); 1303 1304 clear_bit(vid, card->active_vlans); 1305 qeth_l3_set_rx_mode(dev); 1306 return 0; 1307 } 1308 1309 static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb, 1310 struct qeth_hdr *hdr) 1311 { 1312 if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) { 1313 u16 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 : 1314 ETH_P_IP; 1315 unsigned char tg_addr[ETH_ALEN]; 1316 1317 skb_reset_network_header(skb); 1318 switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) { 1319 case QETH_CAST_MULTICAST: 1320 if (prot == ETH_P_IP) 1321 ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr); 1322 else 1323 ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr); 1324 QETH_CARD_STAT_INC(card, rx_multicast); 1325 break; 1326 case QETH_CAST_BROADCAST: 1327 ether_addr_copy(tg_addr, card->dev->broadcast); 1328 QETH_CARD_STAT_INC(card, rx_multicast); 1329 break; 1330 default: 1331 if (card->options.sniffer) 1332 skb->pkt_type = PACKET_OTHERHOST; 1333 ether_addr_copy(tg_addr, card->dev->dev_addr); 1334 } 1335 1336 if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR) 1337 card->dev->header_ops->create(skb, card->dev, prot, 1338 tg_addr, &hdr->hdr.l3.next_hop.rx.src_mac, 1339 skb->len); 1340 else 1341 card->dev->header_ops->create(skb, card->dev, prot, 1342 tg_addr, "FAKELL", skb->len); 1343 } 1344 1345 skb->protocol = eth_type_trans(skb, card->dev); 1346 1347 /* copy VLAN tag from hdr into skb */ 1348 if (!card->options.sniffer && 1349 (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME | 1350 QETH_HDR_EXT_INCLUDE_VLAN_TAG))) { 1351 u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ? 1352 hdr->hdr.l3.vlan_id : 1353 hdr->hdr.l3.next_hop.rx.vlan_id; 1354 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag); 1355 } 1356 1357 qeth_rx_csum(card, skb, hdr->hdr.l3.ext_flags); 1358 } 1359 1360 static int qeth_l3_process_inbound_buffer(struct qeth_card *card, 1361 int budget, int *done) 1362 { 1363 struct net_device *dev = card->dev; 1364 int work_done = 0; 1365 struct sk_buff *skb; 1366 struct qeth_hdr *hdr; 1367 unsigned int len; 1368 __u16 magic; 1369 1370 *done = 0; 1371 WARN_ON_ONCE(!budget); 1372 while (budget) { 1373 skb = qeth_core_get_next_skb(card, 1374 &card->qdio.in_q->bufs[card->rx.b_index], 1375 &card->rx.b_element, &card->rx.e_offset, &hdr); 1376 if (!skb) { 1377 *done = 1; 1378 break; 1379 } 1380 switch (hdr->hdr.l3.id) { 1381 case QETH_HEADER_TYPE_LAYER3: 1382 magic = *(__u16 *)skb->data; 1383 if (IS_IQD(card) && magic == ETH_P_AF_IUCV) { 1384 len = skb->len; 1385 dev_hard_header(skb, dev, ETH_P_AF_IUCV, 1386 dev->dev_addr, "FAKELL", len); 1387 skb->protocol = eth_type_trans(skb, dev); 1388 netif_receive_skb(skb); 1389 } else { 1390 qeth_l3_rebuild_skb(card, skb, hdr); 1391 len = skb->len; 1392 napi_gro_receive(&card->napi, skb); 1393 } 1394 break; 1395 case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */ 1396 skb->protocol = eth_type_trans(skb, skb->dev); 1397 len = skb->len; 1398 netif_receive_skb(skb); 1399 break; 1400 default: 1401 dev_kfree_skb_any(skb); 1402 QETH_CARD_TEXT(card, 3, "inbunkno"); 1403 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr)); 1404 continue; 1405 } 1406 work_done++; 1407 budget--; 1408 QETH_CARD_STAT_INC(card, rx_packets); 1409 QETH_CARD_STAT_ADD(card, rx_bytes, len); 1410 } 1411 return work_done; 1412 } 1413 1414 static void qeth_l3_stop_card(struct qeth_card *card) 1415 { 1416 QETH_DBF_TEXT(SETUP, 2, "stopcard"); 1417 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); 1418 1419 qeth_set_allowed_threads(card, 0, 1); 1420 1421 cancel_work_sync(&card->rx_mode_work); 1422 qeth_l3_drain_rx_mode_cache(card); 1423 1424 if (card->options.sniffer && 1425 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) 1426 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE); 1427 1428 if (card->state == CARD_STATE_SOFTSETUP) { 1429 qeth_l3_clear_ip_htable(card, 1); 1430 qeth_clear_ipacmd_list(card); 1431 card->state = CARD_STATE_HARDSETUP; 1432 } 1433 if (card->state == CARD_STATE_HARDSETUP) { 1434 qeth_qdio_clear_card(card, 0); 1435 qeth_drain_output_queues(card); 1436 qeth_clear_working_pool_list(card); 1437 card->state = CARD_STATE_DOWN; 1438 } 1439 if (card->state == CARD_STATE_DOWN) { 1440 qeth_clear_cmd_buffers(&card->read); 1441 qeth_clear_cmd_buffers(&card->write); 1442 } 1443 1444 flush_workqueue(card->event_wq); 1445 } 1446 1447 /* 1448 * test for and Switch promiscuous mode (on or off) 1449 * either for guestlan or HiperSocket Sniffer 1450 */ 1451 static void 1452 qeth_l3_handle_promisc_mode(struct qeth_card *card) 1453 { 1454 struct net_device *dev = card->dev; 1455 1456 if (((dev->flags & IFF_PROMISC) && 1457 (card->info.promisc_mode == SET_PROMISC_MODE_ON)) || 1458 (!(dev->flags & IFF_PROMISC) && 1459 (card->info.promisc_mode == SET_PROMISC_MODE_OFF))) 1460 return; 1461 1462 if (IS_VM_NIC(card)) { /* Guestlan trace */ 1463 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) 1464 qeth_setadp_promisc_mode(card); 1465 } else if (card->options.sniffer && /* HiperSockets trace */ 1466 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) { 1467 if (dev->flags & IFF_PROMISC) { 1468 QETH_CARD_TEXT(card, 3, "+promisc"); 1469 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE); 1470 } else { 1471 QETH_CARD_TEXT(card, 3, "-promisc"); 1472 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE); 1473 } 1474 } 1475 } 1476 1477 static void qeth_l3_rx_mode_work(struct work_struct *work) 1478 { 1479 struct qeth_card *card = container_of(work, struct qeth_card, 1480 rx_mode_work); 1481 struct qeth_ipaddr *addr; 1482 struct hlist_node *tmp; 1483 int i, rc; 1484 1485 QETH_CARD_TEXT(card, 3, "setmulti"); 1486 1487 if (!card->options.sniffer) { 1488 qeth_l3_add_multicast_ipv4(card); 1489 qeth_l3_add_multicast_ipv6(card); 1490 1491 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) { 1492 switch (addr->disp_flag) { 1493 case QETH_DISP_ADDR_DELETE: 1494 rc = qeth_l3_deregister_addr_entry(card, addr); 1495 if (!rc || rc == -ENOENT) { 1496 hash_del(&addr->hnode); 1497 kfree(addr); 1498 } 1499 break; 1500 case QETH_DISP_ADDR_ADD: 1501 rc = qeth_l3_register_addr_entry(card, addr); 1502 if (rc && rc != -ENETDOWN) { 1503 hash_del(&addr->hnode); 1504 kfree(addr); 1505 break; 1506 } 1507 addr->ref_counter = 1; 1508 /* fall through */ 1509 default: 1510 /* for next call to set_rx_mode(): */ 1511 addr->disp_flag = QETH_DISP_ADDR_DELETE; 1512 } 1513 } 1514 1515 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) 1516 return; 1517 } 1518 qeth_l3_handle_promisc_mode(card); 1519 } 1520 1521 static int qeth_l3_arp_makerc(u16 rc) 1522 { 1523 switch (rc) { 1524 case IPA_RC_SUCCESS: 1525 return 0; 1526 case QETH_IPA_ARP_RC_NOTSUPP: 1527 case QETH_IPA_ARP_RC_Q_NOTSUPP: 1528 return -EOPNOTSUPP; 1529 case QETH_IPA_ARP_RC_OUT_OF_RANGE: 1530 return -EINVAL; 1531 case QETH_IPA_ARP_RC_Q_NO_DATA: 1532 return -ENOENT; 1533 default: 1534 return -EIO; 1535 } 1536 } 1537 1538 static int qeth_l3_arp_cmd_cb(struct qeth_card *card, struct qeth_reply *reply, 1539 unsigned long data) 1540 { 1541 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1542 1543 qeth_setassparms_cb(card, reply, data); 1544 return qeth_l3_arp_makerc(cmd->hdr.return_code); 1545 } 1546 1547 static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries) 1548 { 1549 struct qeth_cmd_buffer *iob; 1550 int rc; 1551 1552 QETH_CARD_TEXT(card, 3, "arpstnoe"); 1553 1554 /* 1555 * currently GuestLAN only supports the ARP assist function 1556 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES; 1557 * thus we say EOPNOTSUPP for this ARP function 1558 */ 1559 if (IS_VM_NIC(card)) 1560 return -EOPNOTSUPP; 1561 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { 1562 return -EOPNOTSUPP; 1563 } 1564 1565 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, 1566 IPA_CMD_ASS_ARP_SET_NO_ENTRIES, 4, 1567 QETH_PROT_IPV4); 1568 if (!iob) 1569 return -ENOMEM; 1570 1571 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = (u32) no_entries; 1572 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL); 1573 if (rc) 1574 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n", 1575 CARD_DEVID(card), rc); 1576 return rc; 1577 } 1578 1579 static __u32 get_arp_entry_size(struct qeth_card *card, 1580 struct qeth_arp_query_data *qdata, 1581 struct qeth_arp_entrytype *type, __u8 strip_entries) 1582 { 1583 __u32 rc; 1584 __u8 is_hsi; 1585 1586 is_hsi = qdata->reply_bits == 5; 1587 if (type->ip == QETHARP_IP_ADDR_V4) { 1588 QETH_CARD_TEXT(card, 4, "arpev4"); 1589 if (strip_entries) { 1590 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) : 1591 sizeof(struct qeth_arp_qi_entry7_short); 1592 } else { 1593 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) : 1594 sizeof(struct qeth_arp_qi_entry7); 1595 } 1596 } else if (type->ip == QETHARP_IP_ADDR_V6) { 1597 QETH_CARD_TEXT(card, 4, "arpev6"); 1598 if (strip_entries) { 1599 rc = is_hsi ? 1600 sizeof(struct qeth_arp_qi_entry5_short_ipv6) : 1601 sizeof(struct qeth_arp_qi_entry7_short_ipv6); 1602 } else { 1603 rc = is_hsi ? 1604 sizeof(struct qeth_arp_qi_entry5_ipv6) : 1605 sizeof(struct qeth_arp_qi_entry7_ipv6); 1606 } 1607 } else { 1608 QETH_CARD_TEXT(card, 4, "arpinv"); 1609 rc = 0; 1610 } 1611 1612 return rc; 1613 } 1614 1615 static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot) 1616 { 1617 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) || 1618 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6); 1619 } 1620 1621 static int qeth_l3_arp_query_cb(struct qeth_card *card, 1622 struct qeth_reply *reply, unsigned long data) 1623 { 1624 struct qeth_ipa_cmd *cmd; 1625 struct qeth_arp_query_data *qdata; 1626 struct qeth_arp_query_info *qinfo; 1627 int e; 1628 int entrybytes_done; 1629 int stripped_bytes; 1630 __u8 do_strip_entries; 1631 1632 QETH_CARD_TEXT(card, 3, "arpquecb"); 1633 1634 qinfo = (struct qeth_arp_query_info *) reply->param; 1635 cmd = (struct qeth_ipa_cmd *) data; 1636 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version); 1637 if (cmd->hdr.return_code) { 1638 QETH_CARD_TEXT(card, 4, "arpcberr"); 1639 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code); 1640 return qeth_l3_arp_makerc(cmd->hdr.return_code); 1641 } 1642 if (cmd->data.setassparms.hdr.return_code) { 1643 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code; 1644 QETH_CARD_TEXT(card, 4, "setaperr"); 1645 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code); 1646 return qeth_l3_arp_makerc(cmd->hdr.return_code); 1647 } 1648 qdata = &cmd->data.setassparms.data.query_arp; 1649 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries); 1650 1651 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0; 1652 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0; 1653 entrybytes_done = 0; 1654 for (e = 0; e < qdata->no_entries; ++e) { 1655 char *cur_entry; 1656 __u32 esize; 1657 struct qeth_arp_entrytype *etype; 1658 1659 cur_entry = &qdata->data + entrybytes_done; 1660 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type; 1661 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) { 1662 QETH_CARD_TEXT(card, 4, "pmis"); 1663 QETH_CARD_TEXT_(card, 4, "%i", etype->ip); 1664 break; 1665 } 1666 esize = get_arp_entry_size(card, qdata, etype, 1667 do_strip_entries); 1668 QETH_CARD_TEXT_(card, 5, "esz%i", esize); 1669 if (!esize) 1670 break; 1671 1672 if ((qinfo->udata_len - qinfo->udata_offset) < esize) { 1673 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOSPC); 1674 memset(qinfo->udata, 0, 4); 1675 return -ENOSPC; 1676 } 1677 1678 memcpy(qinfo->udata + qinfo->udata_offset, 1679 &qdata->data + entrybytes_done + stripped_bytes, 1680 esize); 1681 entrybytes_done += esize + stripped_bytes; 1682 qinfo->udata_offset += esize; 1683 ++qinfo->no_entries; 1684 } 1685 /* check if all replies received ... */ 1686 if (cmd->data.setassparms.hdr.seq_no < 1687 cmd->data.setassparms.hdr.number_of_replies) 1688 return 1; 1689 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries); 1690 memcpy(qinfo->udata, &qinfo->no_entries, 4); 1691 /* keep STRIP_ENTRIES flag so the user program can distinguish 1692 * stripped entries from normal ones */ 1693 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) 1694 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES; 1695 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2); 1696 QETH_CARD_TEXT_(card, 4, "rc%i", 0); 1697 return 0; 1698 } 1699 1700 static int qeth_l3_query_arp_cache_info(struct qeth_card *card, 1701 enum qeth_prot_versions prot, 1702 struct qeth_arp_query_info *qinfo) 1703 { 1704 struct qeth_cmd_buffer *iob; 1705 struct qeth_ipa_cmd *cmd; 1706 int rc; 1707 1708 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot); 1709 1710 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, 1711 IPA_CMD_ASS_ARP_QUERY_INFO, 1712 sizeof(struct qeth_arp_query_data) 1713 - sizeof(char), 1714 prot); 1715 if (!iob) 1716 return -ENOMEM; 1717 cmd = __ipa_cmd(iob); 1718 cmd->data.setassparms.data.query_arp.request_bits = 0x000F; 1719 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_query_cb, qinfo); 1720 if (rc) 1721 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n", 1722 CARD_DEVID(card), rc); 1723 return rc; 1724 } 1725 1726 static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata) 1727 { 1728 struct qeth_arp_query_info qinfo = {0, }; 1729 int rc; 1730 1731 QETH_CARD_TEXT(card, 3, "arpquery"); 1732 1733 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/ 1734 IPA_ARP_PROCESSING)) { 1735 QETH_CARD_TEXT(card, 3, "arpqnsup"); 1736 rc = -EOPNOTSUPP; 1737 goto out; 1738 } 1739 /* get size of userspace buffer and mask_bits -> 6 bytes */ 1740 if (copy_from_user(&qinfo, udata, 6)) { 1741 rc = -EFAULT; 1742 goto out; 1743 } 1744 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL); 1745 if (!qinfo.udata) { 1746 rc = -ENOMEM; 1747 goto out; 1748 } 1749 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET; 1750 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo); 1751 if (rc) { 1752 if (copy_to_user(udata, qinfo.udata, 4)) 1753 rc = -EFAULT; 1754 goto free_and_out; 1755 } 1756 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) { 1757 /* fails in case of GuestLAN QDIO mode */ 1758 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo); 1759 } 1760 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) { 1761 QETH_CARD_TEXT(card, 4, "qactf"); 1762 rc = -EFAULT; 1763 goto free_and_out; 1764 } 1765 QETH_CARD_TEXT(card, 4, "qacts"); 1766 1767 free_and_out: 1768 kfree(qinfo.udata); 1769 out: 1770 return rc; 1771 } 1772 1773 static int qeth_l3_arp_modify_entry(struct qeth_card *card, 1774 struct qeth_arp_cache_entry *entry, 1775 enum qeth_arp_process_subcmds arp_cmd) 1776 { 1777 struct qeth_arp_cache_entry *cmd_entry; 1778 struct qeth_cmd_buffer *iob; 1779 int rc; 1780 1781 if (arp_cmd == IPA_CMD_ASS_ARP_ADD_ENTRY) 1782 QETH_CARD_TEXT(card, 3, "arpadd"); 1783 else 1784 QETH_CARD_TEXT(card, 3, "arpdel"); 1785 1786 /* 1787 * currently GuestLAN only supports the ARP assist function 1788 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY; 1789 * thus we say EOPNOTSUPP for this ARP function 1790 */ 1791 if (IS_VM_NIC(card)) 1792 return -EOPNOTSUPP; 1793 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { 1794 return -EOPNOTSUPP; 1795 } 1796 1797 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, arp_cmd, 1798 sizeof(*cmd_entry), QETH_PROT_IPV4); 1799 if (!iob) 1800 return -ENOMEM; 1801 1802 cmd_entry = &__ipa_cmd(iob)->data.setassparms.data.arp_entry; 1803 ether_addr_copy(cmd_entry->macaddr, entry->macaddr); 1804 memcpy(cmd_entry->ipaddr, entry->ipaddr, 4); 1805 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL); 1806 if (rc) 1807 QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n", 1808 arp_cmd, CARD_DEVID(card), rc); 1809 return rc; 1810 } 1811 1812 static int qeth_l3_arp_flush_cache(struct qeth_card *card) 1813 { 1814 struct qeth_cmd_buffer *iob; 1815 int rc; 1816 1817 QETH_CARD_TEXT(card, 3, "arpflush"); 1818 1819 /* 1820 * currently GuestLAN only supports the ARP assist function 1821 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE; 1822 * thus we say EOPNOTSUPP for this ARP function 1823 */ 1824 if (IS_VM_NIC(card) || IS_IQD(card)) 1825 return -EOPNOTSUPP; 1826 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { 1827 return -EOPNOTSUPP; 1828 } 1829 1830 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, 1831 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0, 1832 QETH_PROT_IPV4); 1833 if (!iob) 1834 return -ENOMEM; 1835 1836 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL); 1837 if (rc) 1838 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n", 1839 CARD_DEVID(card), rc); 1840 return rc; 1841 } 1842 1843 static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1844 { 1845 struct qeth_card *card = dev->ml_priv; 1846 struct qeth_arp_cache_entry arp_entry; 1847 enum qeth_arp_process_subcmds arp_cmd; 1848 int rc = 0; 1849 1850 switch (cmd) { 1851 case SIOC_QETH_ARP_SET_NO_ENTRIES: 1852 if (!capable(CAP_NET_ADMIN)) { 1853 rc = -EPERM; 1854 break; 1855 } 1856 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue); 1857 break; 1858 case SIOC_QETH_ARP_QUERY_INFO: 1859 if (!capable(CAP_NET_ADMIN)) { 1860 rc = -EPERM; 1861 break; 1862 } 1863 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data); 1864 break; 1865 case SIOC_QETH_ARP_ADD_ENTRY: 1866 case SIOC_QETH_ARP_REMOVE_ENTRY: 1867 if (!capable(CAP_NET_ADMIN)) 1868 return -EPERM; 1869 if (copy_from_user(&arp_entry, rq->ifr_data, sizeof(arp_entry))) 1870 return -EFAULT; 1871 1872 arp_cmd = (cmd == SIOC_QETH_ARP_ADD_ENTRY) ? 1873 IPA_CMD_ASS_ARP_ADD_ENTRY : 1874 IPA_CMD_ASS_ARP_REMOVE_ENTRY; 1875 return qeth_l3_arp_modify_entry(card, &arp_entry, arp_cmd); 1876 case SIOC_QETH_ARP_FLUSH_CACHE: 1877 if (!capable(CAP_NET_ADMIN)) { 1878 rc = -EPERM; 1879 break; 1880 } 1881 rc = qeth_l3_arp_flush_cache(card); 1882 break; 1883 default: 1884 rc = -EOPNOTSUPP; 1885 } 1886 return rc; 1887 } 1888 1889 static int qeth_l3_get_cast_type(struct sk_buff *skb) 1890 { 1891 int ipv = qeth_get_ip_version(skb); 1892 struct neighbour *n = NULL; 1893 struct dst_entry *dst; 1894 1895 rcu_read_lock(); 1896 dst = skb_dst(skb); 1897 if (dst) { 1898 struct rt6_info *rt = (struct rt6_info *) dst; 1899 1900 dst = dst_check(dst, (ipv == 6) ? rt6_get_cookie(rt) : 0); 1901 if (dst) 1902 n = dst_neigh_lookup_skb(dst, skb); 1903 } 1904 1905 if (n) { 1906 int cast_type = n->type; 1907 1908 rcu_read_unlock(); 1909 neigh_release(n); 1910 if ((cast_type == RTN_BROADCAST) || 1911 (cast_type == RTN_MULTICAST) || 1912 (cast_type == RTN_ANYCAST)) 1913 return cast_type; 1914 return RTN_UNICAST; 1915 } 1916 rcu_read_unlock(); 1917 1918 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */ 1919 switch (ipv) { 1920 case 4: 1921 if (ipv4_is_lbcast(ip_hdr(skb)->daddr)) 1922 return RTN_BROADCAST; 1923 return ipv4_is_multicast(ip_hdr(skb)->daddr) ? 1924 RTN_MULTICAST : RTN_UNICAST; 1925 case 6: 1926 return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ? 1927 RTN_MULTICAST : RTN_UNICAST; 1928 default: 1929 /* ... and MAC address */ 1930 return qeth_get_ether_cast_type(skb); 1931 } 1932 } 1933 1934 static u8 qeth_l3_cast_type_to_flag(int cast_type) 1935 { 1936 if (cast_type == RTN_MULTICAST) 1937 return QETH_CAST_MULTICAST; 1938 if (cast_type == RTN_ANYCAST) 1939 return QETH_CAST_ANYCAST; 1940 if (cast_type == RTN_BROADCAST) 1941 return QETH_CAST_BROADCAST; 1942 return QETH_CAST_UNICAST; 1943 } 1944 1945 static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue, 1946 struct qeth_hdr *hdr, struct sk_buff *skb, 1947 int ipv, int cast_type, unsigned int data_len) 1948 { 1949 struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3; 1950 struct vlan_ethhdr *veth = vlan_eth_hdr(skb); 1951 struct qeth_card *card = queue->card; 1952 struct dst_entry *dst; 1953 1954 hdr->hdr.l3.length = data_len; 1955 1956 if (skb_is_gso(skb)) { 1957 hdr->hdr.l3.id = QETH_HEADER_TYPE_L3_TSO; 1958 } else { 1959 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3; 1960 1961 if (skb->protocol == htons(ETH_P_AF_IUCV)) { 1962 l3_hdr->flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST; 1963 l3_hdr->next_hop.ipv6_addr.s6_addr16[0] = htons(0xfe80); 1964 memcpy(&l3_hdr->next_hop.ipv6_addr.s6_addr32[2], 1965 iucv_trans_hdr(skb)->destUserID, 8); 1966 return; 1967 } 1968 1969 if (skb->ip_summed == CHECKSUM_PARTIAL) { 1970 qeth_tx_csum(skb, &hdr->hdr.l3.ext_flags, ipv); 1971 /* some HW requires combined L3+L4 csum offload: */ 1972 if (ipv == 4) 1973 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_HDR_REQ; 1974 QETH_TXQ_STAT_INC(queue, skbs_csum); 1975 } 1976 } 1977 1978 if (ipv == 4 || IS_IQD(card)) { 1979 /* NETIF_F_HW_VLAN_CTAG_TX */ 1980 if (skb_vlan_tag_present(skb)) { 1981 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_VLAN_FRAME; 1982 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb); 1983 } 1984 } else if (veth->h_vlan_proto == htons(ETH_P_8021Q)) { 1985 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_INCLUDE_VLAN_TAG; 1986 hdr->hdr.l3.vlan_id = ntohs(veth->h_vlan_TCI); 1987 } 1988 1989 l3_hdr->flags = qeth_l3_cast_type_to_flag(cast_type); 1990 1991 /* OSA only: */ 1992 if (!ipv) { 1993 l3_hdr->flags |= QETH_HDR_PASSTHRU; 1994 return; 1995 } 1996 1997 rcu_read_lock(); 1998 dst = skb_dst(skb); 1999 2000 if (ipv == 4) { 2001 struct rtable *rt; 2002 2003 if (dst) 2004 dst = dst_check(dst, 0); 2005 rt = (struct rtable *) dst; 2006 2007 *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ? 2008 rt_nexthop(rt, ip_hdr(skb)->daddr) : 2009 ip_hdr(skb)->daddr; 2010 } else { 2011 /* IPv6 */ 2012 struct rt6_info *rt; 2013 2014 if (dst) { 2015 rt = (struct rt6_info *) dst; 2016 dst = dst_check(dst, rt6_get_cookie(rt)); 2017 } 2018 rt = (struct rt6_info *) dst; 2019 2020 if (rt && !ipv6_addr_any(&rt->rt6i_gateway)) 2021 l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway; 2022 else 2023 l3_hdr->next_hop.ipv6_addr = ipv6_hdr(skb)->daddr; 2024 2025 hdr->hdr.l3.flags |= QETH_HDR_IPV6; 2026 if (!IS_IQD(card)) 2027 hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU; 2028 } 2029 rcu_read_unlock(); 2030 } 2031 2032 static void qeth_l3_fixup_headers(struct sk_buff *skb) 2033 { 2034 struct iphdr *iph = ip_hdr(skb); 2035 2036 /* this is safe, IPv6 traffic takes a different path */ 2037 if (skb->ip_summed == CHECKSUM_PARTIAL) 2038 iph->check = 0; 2039 if (skb_is_gso(skb)) { 2040 iph->tot_len = 0; 2041 tcp_hdr(skb)->check = ~tcp_v4_check(0, iph->saddr, 2042 iph->daddr, 0); 2043 } 2044 } 2045 2046 static int qeth_l3_xmit(struct qeth_card *card, struct sk_buff *skb, 2047 struct qeth_qdio_out_q *queue, int ipv, int cast_type) 2048 { 2049 unsigned int hw_hdr_len; 2050 int rc; 2051 2052 /* re-use the L2 header area for the HW header: */ 2053 hw_hdr_len = skb_is_gso(skb) ? sizeof(struct qeth_hdr_tso) : 2054 sizeof(struct qeth_hdr); 2055 rc = skb_cow_head(skb, hw_hdr_len - ETH_HLEN); 2056 if (rc) 2057 return rc; 2058 skb_pull(skb, ETH_HLEN); 2059 2060 qeth_l3_fixup_headers(skb); 2061 return qeth_xmit(card, skb, queue, ipv, cast_type, qeth_l3_fill_header); 2062 } 2063 2064 static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb, 2065 struct net_device *dev) 2066 { 2067 struct qeth_card *card = dev->ml_priv; 2068 u16 txq = skb_get_queue_mapping(skb); 2069 int ipv = qeth_get_ip_version(skb); 2070 struct qeth_qdio_out_q *queue; 2071 int tx_bytes = skb->len; 2072 int cast_type, rc; 2073 2074 if (IS_IQD(card)) { 2075 queue = card->qdio.out_qs[qeth_iqd_translate_txq(dev, txq)]; 2076 2077 if (card->options.sniffer) 2078 goto tx_drop; 2079 if ((card->options.cq != QETH_CQ_ENABLED && !ipv) || 2080 (card->options.cq == QETH_CQ_ENABLED && 2081 skb->protocol != htons(ETH_P_AF_IUCV))) 2082 goto tx_drop; 2083 2084 if (txq == QETH_IQD_MCAST_TXQ) 2085 cast_type = qeth_l3_get_cast_type(skb); 2086 else 2087 cast_type = RTN_UNICAST; 2088 } else { 2089 queue = card->qdio.out_qs[txq]; 2090 cast_type = qeth_l3_get_cast_type(skb); 2091 } 2092 2093 if (cast_type == RTN_BROADCAST && !card->info.broadcast_capable) 2094 goto tx_drop; 2095 2096 if (ipv == 4 || IS_IQD(card)) 2097 rc = qeth_l3_xmit(card, skb, queue, ipv, cast_type); 2098 else 2099 rc = qeth_xmit(card, skb, queue, ipv, cast_type, 2100 qeth_l3_fill_header); 2101 2102 if (!rc) { 2103 QETH_TXQ_STAT_INC(queue, tx_packets); 2104 QETH_TXQ_STAT_ADD(queue, tx_bytes, tx_bytes); 2105 return NETDEV_TX_OK; 2106 } 2107 2108 tx_drop: 2109 QETH_TXQ_STAT_INC(queue, tx_dropped); 2110 kfree_skb(skb); 2111 return NETDEV_TX_OK; 2112 } 2113 2114 static void qeth_l3_set_rx_mode(struct net_device *dev) 2115 { 2116 struct qeth_card *card = dev->ml_priv; 2117 2118 schedule_work(&card->rx_mode_work); 2119 } 2120 2121 /* 2122 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting 2123 * NOARP on the netdevice is no option because it also turns off neighbor 2124 * solicitation. For IPv4 we install a neighbor_setup function. We don't want 2125 * arp resolution but we want the hard header (packet socket will work 2126 * e.g. tcpdump) 2127 */ 2128 static int qeth_l3_neigh_setup_noarp(struct neighbour *n) 2129 { 2130 n->nud_state = NUD_NOARP; 2131 memcpy(n->ha, "FAKELL", 6); 2132 n->output = n->ops->connected_output; 2133 return 0; 2134 } 2135 2136 static int 2137 qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np) 2138 { 2139 if (np->tbl->family == AF_INET) 2140 np->neigh_setup = qeth_l3_neigh_setup_noarp; 2141 2142 return 0; 2143 } 2144 2145 static netdev_features_t qeth_l3_osa_features_check(struct sk_buff *skb, 2146 struct net_device *dev, 2147 netdev_features_t features) 2148 { 2149 if (qeth_get_ip_version(skb) != 4) 2150 features &= ~NETIF_F_HW_VLAN_CTAG_TX; 2151 return qeth_features_check(skb, dev, features); 2152 } 2153 2154 static u16 qeth_l3_iqd_select_queue(struct net_device *dev, struct sk_buff *skb, 2155 struct net_device *sb_dev) 2156 { 2157 return qeth_iqd_select_queue(dev, skb, qeth_l3_get_cast_type(skb), 2158 sb_dev); 2159 } 2160 2161 static u16 qeth_l3_osa_select_queue(struct net_device *dev, struct sk_buff *skb, 2162 struct net_device *sb_dev) 2163 { 2164 struct qeth_card *card = dev->ml_priv; 2165 2166 return qeth_get_priority_queue(card, skb); 2167 } 2168 2169 static const struct net_device_ops qeth_l3_netdev_ops = { 2170 .ndo_open = qeth_open, 2171 .ndo_stop = qeth_stop, 2172 .ndo_get_stats64 = qeth_get_stats64, 2173 .ndo_start_xmit = qeth_l3_hard_start_xmit, 2174 .ndo_select_queue = qeth_l3_iqd_select_queue, 2175 .ndo_validate_addr = eth_validate_addr, 2176 .ndo_set_rx_mode = qeth_l3_set_rx_mode, 2177 .ndo_do_ioctl = qeth_do_ioctl, 2178 .ndo_fix_features = qeth_fix_features, 2179 .ndo_set_features = qeth_set_features, 2180 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid, 2181 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid, 2182 .ndo_tx_timeout = qeth_tx_timeout, 2183 }; 2184 2185 static const struct net_device_ops qeth_l3_osa_netdev_ops = { 2186 .ndo_open = qeth_open, 2187 .ndo_stop = qeth_stop, 2188 .ndo_get_stats64 = qeth_get_stats64, 2189 .ndo_start_xmit = qeth_l3_hard_start_xmit, 2190 .ndo_features_check = qeth_l3_osa_features_check, 2191 .ndo_select_queue = qeth_l3_osa_select_queue, 2192 .ndo_validate_addr = eth_validate_addr, 2193 .ndo_set_rx_mode = qeth_l3_set_rx_mode, 2194 .ndo_do_ioctl = qeth_do_ioctl, 2195 .ndo_fix_features = qeth_fix_features, 2196 .ndo_set_features = qeth_set_features, 2197 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid, 2198 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid, 2199 .ndo_tx_timeout = qeth_tx_timeout, 2200 .ndo_neigh_setup = qeth_l3_neigh_setup, 2201 }; 2202 2203 static int qeth_l3_setup_netdev(struct qeth_card *card, bool carrier_ok) 2204 { 2205 unsigned int headroom; 2206 int rc; 2207 2208 if (IS_OSD(card) || IS_OSX(card)) { 2209 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) || 2210 (card->info.link_type == QETH_LINK_TYPE_HSTR)) { 2211 pr_info("qeth_l3: ignoring TR device\n"); 2212 return -ENODEV; 2213 } 2214 2215 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops; 2216 2217 /*IPv6 address autoconfiguration stuff*/ 2218 qeth_l3_get_unique_id(card); 2219 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD)) 2220 card->dev->dev_id = card->info.unique_id & 0xffff; 2221 2222 if (!IS_VM_NIC(card)) { 2223 card->dev->features |= NETIF_F_SG; 2224 card->dev->hw_features |= NETIF_F_TSO | 2225 NETIF_F_RXCSUM | NETIF_F_IP_CSUM; 2226 card->dev->vlan_features |= NETIF_F_TSO | 2227 NETIF_F_RXCSUM | NETIF_F_IP_CSUM; 2228 } 2229 2230 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) { 2231 card->dev->hw_features |= NETIF_F_IPV6_CSUM; 2232 card->dev->vlan_features |= NETIF_F_IPV6_CSUM; 2233 } 2234 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) { 2235 card->dev->hw_features |= NETIF_F_TSO6; 2236 card->dev->vlan_features |= NETIF_F_TSO6; 2237 } 2238 2239 /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */ 2240 if (card->dev->hw_features & NETIF_F_TSO6) 2241 headroom = sizeof(struct qeth_hdr_tso) + VLAN_HLEN; 2242 else if (card->dev->hw_features & NETIF_F_TSO) 2243 headroom = sizeof(struct qeth_hdr_tso); 2244 else 2245 headroom = sizeof(struct qeth_hdr) + VLAN_HLEN; 2246 } else if (IS_IQD(card)) { 2247 card->dev->flags |= IFF_NOARP; 2248 card->dev->netdev_ops = &qeth_l3_netdev_ops; 2249 headroom = sizeof(struct qeth_hdr) - ETH_HLEN; 2250 2251 rc = qeth_l3_iqd_read_initial_mac(card); 2252 if (rc) 2253 goto out; 2254 } else 2255 return -ENODEV; 2256 2257 card->dev->needed_headroom = headroom; 2258 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX | 2259 NETIF_F_HW_VLAN_CTAG_RX | 2260 NETIF_F_HW_VLAN_CTAG_FILTER; 2261 2262 netif_keep_dst(card->dev); 2263 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) 2264 netif_set_gso_max_size(card->dev, 2265 PAGE_SIZE * (QETH_MAX_BUFFER_ELEMENTS(card) - 1)); 2266 2267 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); 2268 rc = register_netdev(card->dev); 2269 if (!rc && carrier_ok) 2270 netif_carrier_on(card->dev); 2271 2272 out: 2273 if (rc) 2274 card->dev->netdev_ops = NULL; 2275 return rc; 2276 } 2277 2278 static const struct device_type qeth_l3_devtype = { 2279 .name = "qeth_layer3", 2280 .groups = qeth_l3_attr_groups, 2281 }; 2282 2283 static int qeth_l3_probe_device(struct ccwgroup_device *gdev) 2284 { 2285 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 2286 int rc; 2287 2288 hash_init(card->ip_htable); 2289 mutex_init(&card->ip_lock); 2290 card->cmd_wq = alloc_ordered_workqueue("%s_cmd", 0, 2291 dev_name(&gdev->dev)); 2292 if (!card->cmd_wq) 2293 return -ENOMEM; 2294 2295 if (gdev->dev.type == &qeth_generic_devtype) { 2296 rc = qeth_l3_create_device_attributes(&gdev->dev); 2297 if (rc) { 2298 destroy_workqueue(card->cmd_wq); 2299 return rc; 2300 } 2301 } 2302 2303 hash_init(card->ip_mc_htable); 2304 INIT_WORK(&card->rx_mode_work, qeth_l3_rx_mode_work); 2305 return 0; 2306 } 2307 2308 static void qeth_l3_remove_device(struct ccwgroup_device *cgdev) 2309 { 2310 struct qeth_card *card = dev_get_drvdata(&cgdev->dev); 2311 2312 if (cgdev->dev.type == &qeth_generic_devtype) 2313 qeth_l3_remove_device_attributes(&cgdev->dev); 2314 2315 qeth_set_allowed_threads(card, 0, 1); 2316 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); 2317 2318 if (cgdev->state == CCWGROUP_ONLINE) 2319 qeth_l3_set_offline(cgdev); 2320 2321 cancel_work_sync(&card->close_dev_work); 2322 if (qeth_netdev_is_registered(card->dev)) 2323 unregister_netdev(card->dev); 2324 2325 flush_workqueue(card->cmd_wq); 2326 destroy_workqueue(card->cmd_wq); 2327 qeth_l3_clear_ip_htable(card, 0); 2328 qeth_l3_clear_ipato_list(card); 2329 } 2330 2331 static int qeth_l3_set_online(struct ccwgroup_device *gdev) 2332 { 2333 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 2334 struct net_device *dev = card->dev; 2335 int rc = 0; 2336 bool carrier_ok; 2337 2338 mutex_lock(&card->discipline_mutex); 2339 mutex_lock(&card->conf_mutex); 2340 QETH_DBF_TEXT(SETUP, 2, "setonlin"); 2341 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); 2342 2343 rc = qeth_core_hardsetup_card(card, &carrier_ok); 2344 if (rc) { 2345 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc); 2346 rc = -ENODEV; 2347 goto out_remove; 2348 } 2349 2350 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) { 2351 if (card->info.hwtrap && 2352 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)) 2353 card->info.hwtrap = 0; 2354 } else 2355 card->info.hwtrap = 0; 2356 2357 card->state = CARD_STATE_HARDSETUP; 2358 qeth_print_status_message(card); 2359 2360 /* softsetup */ 2361 QETH_DBF_TEXT(SETUP, 2, "softsetp"); 2362 2363 rc = qeth_l3_setadapter_parms(card); 2364 if (rc) 2365 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc); 2366 if (!card->options.sniffer) { 2367 rc = qeth_l3_start_ipassists(card); 2368 if (rc) { 2369 QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc); 2370 goto out_remove; 2371 } 2372 rc = qeth_l3_setrouting_v4(card); 2373 if (rc) 2374 QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc); 2375 rc = qeth_l3_setrouting_v6(card); 2376 if (rc) 2377 QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc); 2378 } 2379 2380 rc = qeth_init_qdio_queues(card); 2381 if (rc) { 2382 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc); 2383 rc = -ENODEV; 2384 goto out_remove; 2385 } 2386 card->state = CARD_STATE_SOFTSETUP; 2387 2388 qeth_set_allowed_threads(card, 0xffffffff, 0); 2389 qeth_l3_recover_ip(card); 2390 2391 if (!qeth_netdev_is_registered(dev)) { 2392 rc = qeth_l3_setup_netdev(card, carrier_ok); 2393 if (rc) 2394 goto out_remove; 2395 } else { 2396 rtnl_lock(); 2397 if (carrier_ok) 2398 netif_carrier_on(dev); 2399 else 2400 netif_carrier_off(dev); 2401 2402 netif_device_attach(dev); 2403 qeth_enable_hw_features(dev); 2404 2405 if (card->info.open_when_online) { 2406 card->info.open_when_online = 0; 2407 dev_open(dev, NULL); 2408 } 2409 rtnl_unlock(); 2410 } 2411 qeth_trace_features(card); 2412 /* let user_space know that device is online */ 2413 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); 2414 mutex_unlock(&card->conf_mutex); 2415 mutex_unlock(&card->discipline_mutex); 2416 return 0; 2417 out_remove: 2418 qeth_l3_stop_card(card); 2419 ccw_device_set_offline(CARD_DDEV(card)); 2420 ccw_device_set_offline(CARD_WDEV(card)); 2421 ccw_device_set_offline(CARD_RDEV(card)); 2422 qdio_free(CARD_DDEV(card)); 2423 card->state = CARD_STATE_DOWN; 2424 2425 mutex_unlock(&card->conf_mutex); 2426 mutex_unlock(&card->discipline_mutex); 2427 return rc; 2428 } 2429 2430 static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev, 2431 int recovery_mode) 2432 { 2433 struct qeth_card *card = dev_get_drvdata(&cgdev->dev); 2434 int rc = 0, rc2 = 0, rc3 = 0; 2435 2436 mutex_lock(&card->discipline_mutex); 2437 mutex_lock(&card->conf_mutex); 2438 QETH_DBF_TEXT(SETUP, 3, "setoffl"); 2439 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *)); 2440 2441 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) { 2442 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 2443 card->info.hwtrap = 1; 2444 } 2445 2446 rtnl_lock(); 2447 card->info.open_when_online = card->dev->flags & IFF_UP; 2448 dev_close(card->dev); 2449 netif_device_detach(card->dev); 2450 netif_carrier_off(card->dev); 2451 rtnl_unlock(); 2452 2453 qeth_l3_stop_card(card); 2454 if (card->options.cq == QETH_CQ_ENABLED) { 2455 rtnl_lock(); 2456 call_netdevice_notifiers(NETDEV_REBOOT, card->dev); 2457 rtnl_unlock(); 2458 } 2459 rc = ccw_device_set_offline(CARD_DDEV(card)); 2460 rc2 = ccw_device_set_offline(CARD_WDEV(card)); 2461 rc3 = ccw_device_set_offline(CARD_RDEV(card)); 2462 if (!rc) 2463 rc = (rc2) ? rc2 : rc3; 2464 if (rc) 2465 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); 2466 qdio_free(CARD_DDEV(card)); 2467 2468 /* let user_space know that device is offline */ 2469 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE); 2470 mutex_unlock(&card->conf_mutex); 2471 mutex_unlock(&card->discipline_mutex); 2472 return 0; 2473 } 2474 2475 static int qeth_l3_set_offline(struct ccwgroup_device *cgdev) 2476 { 2477 return __qeth_l3_set_offline(cgdev, 0); 2478 } 2479 2480 static int qeth_l3_recover(void *ptr) 2481 { 2482 struct qeth_card *card; 2483 int rc = 0; 2484 2485 card = (struct qeth_card *) ptr; 2486 QETH_CARD_TEXT(card, 2, "recover1"); 2487 QETH_CARD_HEX(card, 2, &card, sizeof(void *)); 2488 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) 2489 return 0; 2490 QETH_CARD_TEXT(card, 2, "recover2"); 2491 dev_warn(&card->gdev->dev, 2492 "A recovery process has been started for the device\n"); 2493 __qeth_l3_set_offline(card->gdev, 1); 2494 rc = qeth_l3_set_online(card->gdev); 2495 if (!rc) 2496 dev_info(&card->gdev->dev, 2497 "Device successfully recovered!\n"); 2498 else { 2499 ccwgroup_set_offline(card->gdev); 2500 dev_warn(&card->gdev->dev, "The qeth device driver " 2501 "failed to recover an error on the device\n"); 2502 } 2503 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); 2504 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); 2505 return 0; 2506 } 2507 2508 static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev) 2509 { 2510 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 2511 2512 qeth_set_allowed_threads(card, 0, 1); 2513 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); 2514 if (gdev->state == CCWGROUP_OFFLINE) 2515 return 0; 2516 2517 qeth_l3_set_offline(gdev); 2518 return 0; 2519 } 2520 2521 static int qeth_l3_pm_resume(struct ccwgroup_device *gdev) 2522 { 2523 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 2524 int rc; 2525 2526 rc = qeth_l3_set_online(gdev); 2527 2528 qeth_set_allowed_threads(card, 0xffffffff, 0); 2529 if (rc) 2530 dev_warn(&card->gdev->dev, "The qeth device driver " 2531 "failed to recover an error on the device\n"); 2532 return rc; 2533 } 2534 2535 /* Returns zero if the command is successfully "consumed" */ 2536 static int qeth_l3_control_event(struct qeth_card *card, 2537 struct qeth_ipa_cmd *cmd) 2538 { 2539 return 1; 2540 } 2541 2542 struct qeth_discipline qeth_l3_discipline = { 2543 .devtype = &qeth_l3_devtype, 2544 .process_rx_buffer = qeth_l3_process_inbound_buffer, 2545 .recover = qeth_l3_recover, 2546 .setup = qeth_l3_probe_device, 2547 .remove = qeth_l3_remove_device, 2548 .set_online = qeth_l3_set_online, 2549 .set_offline = qeth_l3_set_offline, 2550 .freeze = qeth_l3_pm_suspend, 2551 .thaw = qeth_l3_pm_resume, 2552 .restore = qeth_l3_pm_resume, 2553 .do_ioctl = qeth_l3_do_ioctl, 2554 .control_event_handler = qeth_l3_control_event, 2555 }; 2556 EXPORT_SYMBOL_GPL(qeth_l3_discipline); 2557 2558 static int qeth_l3_handle_ip_event(struct qeth_card *card, 2559 struct qeth_ipaddr *addr, 2560 unsigned long event) 2561 { 2562 switch (event) { 2563 case NETDEV_UP: 2564 qeth_l3_modify_ip(card, addr, true); 2565 return NOTIFY_OK; 2566 case NETDEV_DOWN: 2567 qeth_l3_modify_ip(card, addr, false); 2568 return NOTIFY_OK; 2569 default: 2570 return NOTIFY_DONE; 2571 } 2572 } 2573 2574 struct qeth_l3_ip_event_work { 2575 struct work_struct work; 2576 struct qeth_card *card; 2577 struct qeth_ipaddr addr; 2578 }; 2579 2580 #define to_ip_work(w) container_of((w), struct qeth_l3_ip_event_work, work) 2581 2582 static void qeth_l3_add_ip_worker(struct work_struct *work) 2583 { 2584 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work); 2585 2586 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, true); 2587 kfree(work); 2588 } 2589 2590 static void qeth_l3_delete_ip_worker(struct work_struct *work) 2591 { 2592 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work); 2593 2594 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, false); 2595 kfree(work); 2596 } 2597 2598 static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev) 2599 { 2600 if (is_vlan_dev(dev)) 2601 dev = vlan_dev_real_dev(dev); 2602 if (dev->netdev_ops == &qeth_l3_osa_netdev_ops || 2603 dev->netdev_ops == &qeth_l3_netdev_ops) 2604 return (struct qeth_card *) dev->ml_priv; 2605 return NULL; 2606 } 2607 2608 static int qeth_l3_ip_event(struct notifier_block *this, 2609 unsigned long event, void *ptr) 2610 { 2611 2612 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; 2613 struct net_device *dev = ifa->ifa_dev->dev; 2614 struct qeth_ipaddr addr; 2615 struct qeth_card *card; 2616 2617 if (dev_net(dev) != &init_net) 2618 return NOTIFY_DONE; 2619 2620 card = qeth_l3_get_card_from_dev(dev); 2621 if (!card) 2622 return NOTIFY_DONE; 2623 QETH_CARD_TEXT(card, 3, "ipevent"); 2624 2625 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4); 2626 addr.u.a4.addr = be32_to_cpu(ifa->ifa_address); 2627 addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask); 2628 2629 return qeth_l3_handle_ip_event(card, &addr, event); 2630 } 2631 2632 static struct notifier_block qeth_l3_ip_notifier = { 2633 qeth_l3_ip_event, 2634 NULL, 2635 }; 2636 2637 static int qeth_l3_ip6_event(struct notifier_block *this, 2638 unsigned long event, void *ptr) 2639 { 2640 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; 2641 struct net_device *dev = ifa->idev->dev; 2642 struct qeth_l3_ip_event_work *ip_work; 2643 struct qeth_card *card; 2644 2645 if (event != NETDEV_UP && event != NETDEV_DOWN) 2646 return NOTIFY_DONE; 2647 2648 card = qeth_l3_get_card_from_dev(dev); 2649 if (!card) 2650 return NOTIFY_DONE; 2651 QETH_CARD_TEXT(card, 3, "ip6event"); 2652 if (!qeth_is_supported(card, IPA_IPV6)) 2653 return NOTIFY_DONE; 2654 2655 ip_work = kmalloc(sizeof(*ip_work), GFP_ATOMIC); 2656 if (!ip_work) 2657 return NOTIFY_DONE; 2658 2659 if (event == NETDEV_UP) 2660 INIT_WORK(&ip_work->work, qeth_l3_add_ip_worker); 2661 else 2662 INIT_WORK(&ip_work->work, qeth_l3_delete_ip_worker); 2663 2664 ip_work->card = card; 2665 qeth_l3_init_ipaddr(&ip_work->addr, QETH_IP_TYPE_NORMAL, 2666 QETH_PROT_IPV6); 2667 ip_work->addr.u.a6.addr = ifa->addr; 2668 ip_work->addr.u.a6.pfxlen = ifa->prefix_len; 2669 2670 queue_work(card->cmd_wq, &ip_work->work); 2671 return NOTIFY_OK; 2672 } 2673 2674 static struct notifier_block qeth_l3_ip6_notifier = { 2675 qeth_l3_ip6_event, 2676 NULL, 2677 }; 2678 2679 static int qeth_l3_register_notifiers(void) 2680 { 2681 int rc; 2682 2683 QETH_DBF_TEXT(SETUP, 5, "regnotif"); 2684 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier); 2685 if (rc) 2686 return rc; 2687 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier); 2688 if (rc) { 2689 unregister_inetaddr_notifier(&qeth_l3_ip_notifier); 2690 return rc; 2691 } 2692 return 0; 2693 } 2694 2695 static void qeth_l3_unregister_notifiers(void) 2696 { 2697 QETH_DBF_TEXT(SETUP, 5, "unregnot"); 2698 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier)); 2699 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier)); 2700 } 2701 2702 static int __init qeth_l3_init(void) 2703 { 2704 pr_info("register layer 3 discipline\n"); 2705 return qeth_l3_register_notifiers(); 2706 } 2707 2708 static void __exit qeth_l3_exit(void) 2709 { 2710 qeth_l3_unregister_notifiers(); 2711 pr_info("unregister layer 3 discipline\n"); 2712 } 2713 2714 module_init(qeth_l3_init); 2715 module_exit(qeth_l3_exit); 2716 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); 2717 MODULE_DESCRIPTION("qeth layer 3 discipline"); 2718 MODULE_LICENSE("GPL"); 2719