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