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