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