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