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