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