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