1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright IBM Corp. 2007, 2009 4 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>, 5 * Frank Pavlic <fpavlic@de.ibm.com>, 6 * Thomas Spatzier <tspat@de.ibm.com>, 7 * Frank Blaschka <frank.blaschka@de.ibm.com> 8 */ 9 10 #define KMSG_COMPONENT "qeth" 11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 12 13 #include <linux/module.h> 14 #include <linux/moduleparam.h> 15 #include <linux/string.h> 16 #include <linux/errno.h> 17 #include <linux/kernel.h> 18 #include <linux/slab.h> 19 #include <linux/etherdevice.h> 20 #include <linux/list.h> 21 #include <linux/hash.h> 22 #include <linux/hashtable.h> 23 #include <asm/setup.h> 24 #include "qeth_core.h" 25 #include "qeth_l2.h" 26 27 static void qeth_bridgeport_query_support(struct qeth_card *card); 28 static void qeth_bridge_state_change(struct qeth_card *card, 29 struct qeth_ipa_cmd *cmd); 30 static void qeth_bridge_host_event(struct qeth_card *card, 31 struct qeth_ipa_cmd *cmd); 32 static void qeth_l2_vnicc_set_defaults(struct qeth_card *card); 33 static void qeth_l2_vnicc_init(struct qeth_card *card); 34 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc, 35 u32 *timeout); 36 37 static int qeth_l2_setdelmac_makerc(struct qeth_card *card, u16 retcode) 38 { 39 int rc; 40 41 if (retcode) 42 QETH_CARD_TEXT_(card, 2, "err%04x", retcode); 43 switch (retcode) { 44 case IPA_RC_SUCCESS: 45 rc = 0; 46 break; 47 case IPA_RC_L2_UNSUPPORTED_CMD: 48 rc = -EOPNOTSUPP; 49 break; 50 case IPA_RC_L2_ADDR_TABLE_FULL: 51 rc = -ENOSPC; 52 break; 53 case IPA_RC_L2_DUP_MAC: 54 case IPA_RC_L2_DUP_LAYER3_MAC: 55 rc = -EADDRINUSE; 56 break; 57 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP: 58 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: 59 rc = -EADDRNOTAVAIL; 60 break; 61 case IPA_RC_L2_MAC_NOT_FOUND: 62 rc = -ENOENT; 63 break; 64 default: 65 rc = -EIO; 66 break; 67 } 68 return rc; 69 } 70 71 static int qeth_l2_send_setdelmac_cb(struct qeth_card *card, 72 struct qeth_reply *reply, 73 unsigned long data) 74 { 75 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 76 77 return qeth_l2_setdelmac_makerc(card, cmd->hdr.return_code); 78 } 79 80 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac, 81 enum qeth_ipa_cmds ipacmd) 82 { 83 struct qeth_ipa_cmd *cmd; 84 struct qeth_cmd_buffer *iob; 85 86 QETH_CARD_TEXT(card, 2, "L2sdmac"); 87 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4, 88 IPA_DATA_SIZEOF(setdelmac)); 89 if (!iob) 90 return -ENOMEM; 91 cmd = __ipa_cmd(iob); 92 cmd->data.setdelmac.mac_length = ETH_ALEN; 93 ether_addr_copy(cmd->data.setdelmac.mac, mac); 94 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelmac_cb, NULL); 95 } 96 97 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac) 98 { 99 int rc; 100 101 QETH_CARD_TEXT(card, 2, "L2Setmac"); 102 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC); 103 if (rc == 0) { 104 dev_info(&card->gdev->dev, 105 "MAC address %pM successfully registered\n", mac); 106 } else { 107 switch (rc) { 108 case -EADDRINUSE: 109 dev_warn(&card->gdev->dev, 110 "MAC address %pM already exists\n", mac); 111 break; 112 case -EADDRNOTAVAIL: 113 dev_warn(&card->gdev->dev, 114 "MAC address %pM is not authorized\n", mac); 115 break; 116 } 117 } 118 return rc; 119 } 120 121 static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac) 122 { 123 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ? 124 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC; 125 int rc; 126 127 QETH_CARD_TEXT(card, 2, "L2Wmac"); 128 rc = qeth_l2_send_setdelmac(card, mac, cmd); 129 if (rc == -EADDRINUSE) 130 QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n", 131 CARD_DEVID(card)); 132 else if (rc) 133 QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n", 134 CARD_DEVID(card), rc); 135 return rc; 136 } 137 138 static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac) 139 { 140 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ? 141 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC; 142 int rc; 143 144 QETH_CARD_TEXT(card, 2, "L2Rmac"); 145 rc = qeth_l2_send_setdelmac(card, mac, cmd); 146 if (rc) 147 QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n", 148 CARD_DEVID(card), rc); 149 return rc; 150 } 151 152 static void qeth_l2_drain_rx_mode_cache(struct qeth_card *card) 153 { 154 struct qeth_mac *mac; 155 struct hlist_node *tmp; 156 int i; 157 158 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { 159 hash_del(&mac->hnode); 160 kfree(mac); 161 } 162 } 163 164 static void qeth_l2_fill_header(struct qeth_qdio_out_q *queue, 165 struct qeth_hdr *hdr, struct sk_buff *skb, 166 int ipv, unsigned int data_len) 167 { 168 int cast_type = qeth_get_ether_cast_type(skb); 169 struct vlan_ethhdr *veth = vlan_eth_hdr(skb); 170 171 hdr->hdr.l2.pkt_length = data_len; 172 173 if (skb_is_gso(skb)) { 174 hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO; 175 } else { 176 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; 177 if (skb->ip_summed == CHECKSUM_PARTIAL) 178 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv); 179 } 180 181 /* set byte byte 3 to casting flags */ 182 if (cast_type == RTN_MULTICAST) 183 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST; 184 else if (cast_type == RTN_BROADCAST) 185 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST; 186 else 187 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST; 188 189 /* VSWITCH relies on the VLAN 190 * information to be present in 191 * the QDIO header */ 192 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) { 193 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN; 194 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI); 195 } 196 } 197 198 static int qeth_l2_setdelvlan_makerc(struct qeth_card *card, u16 retcode) 199 { 200 if (retcode) 201 QETH_CARD_TEXT_(card, 2, "err%04x", retcode); 202 203 switch (retcode) { 204 case IPA_RC_SUCCESS: 205 return 0; 206 case IPA_RC_L2_INVALID_VLAN_ID: 207 return -EINVAL; 208 case IPA_RC_L2_DUP_VLAN_ID: 209 return -EEXIST; 210 case IPA_RC_L2_VLAN_ID_NOT_FOUND: 211 return -ENOENT; 212 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED: 213 return -EPERM; 214 default: 215 return -EIO; 216 } 217 } 218 219 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card, 220 struct qeth_reply *reply, 221 unsigned long data) 222 { 223 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 224 225 QETH_CARD_TEXT(card, 2, "L2sdvcb"); 226 if (cmd->hdr.return_code) { 227 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n", 228 cmd->data.setdelvlan.vlan_id, 229 CARD_DEVID(card), cmd->hdr.return_code); 230 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command); 231 } 232 return qeth_l2_setdelvlan_makerc(card, cmd->hdr.return_code); 233 } 234 235 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i, 236 enum qeth_ipa_cmds ipacmd) 237 { 238 struct qeth_ipa_cmd *cmd; 239 struct qeth_cmd_buffer *iob; 240 241 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd); 242 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4, 243 IPA_DATA_SIZEOF(setdelvlan)); 244 if (!iob) 245 return -ENOMEM; 246 cmd = __ipa_cmd(iob); 247 cmd->data.setdelvlan.vlan_id = i; 248 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelvlan_cb, NULL); 249 } 250 251 static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, 252 __be16 proto, u16 vid) 253 { 254 struct qeth_card *card = dev->ml_priv; 255 256 QETH_CARD_TEXT_(card, 4, "aid:%d", vid); 257 if (!vid) 258 return 0; 259 260 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); 261 } 262 263 static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, 264 __be16 proto, u16 vid) 265 { 266 struct qeth_card *card = dev->ml_priv; 267 268 QETH_CARD_TEXT_(card, 4, "kid:%d", vid); 269 if (!vid) 270 return 0; 271 272 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); 273 } 274 275 static void qeth_l2_stop_card(struct qeth_card *card) 276 { 277 QETH_CARD_TEXT(card, 2, "stopcard"); 278 279 qeth_set_allowed_threads(card, 0, 1); 280 281 cancel_work_sync(&card->rx_mode_work); 282 qeth_l2_drain_rx_mode_cache(card); 283 284 if (card->state == CARD_STATE_SOFTSETUP) { 285 qeth_clear_ipacmd_list(card); 286 qeth_drain_output_queues(card); 287 cancel_delayed_work_sync(&card->buffer_reclaim_work); 288 card->state = CARD_STATE_DOWN; 289 } 290 291 qeth_qdio_clear_card(card, 0); 292 qeth_clear_working_pool_list(card); 293 flush_workqueue(card->event_wq); 294 qeth_flush_local_addrs(card); 295 card->info.promisc_mode = 0; 296 } 297 298 static int qeth_l2_request_initial_mac(struct qeth_card *card) 299 { 300 int rc = 0; 301 302 QETH_CARD_TEXT(card, 2, "l2reqmac"); 303 304 if (MACHINE_IS_VM) { 305 rc = qeth_vm_request_mac(card); 306 if (!rc) 307 goto out; 308 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n", 309 CARD_DEVID(card), rc); 310 QETH_CARD_TEXT_(card, 2, "err%04x", rc); 311 /* fall back to alternative mechanism: */ 312 } 313 314 if (!IS_OSN(card)) { 315 rc = qeth_setadpparms_change_macaddr(card); 316 if (!rc) 317 goto out; 318 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n", 319 CARD_DEVID(card), rc); 320 QETH_CARD_TEXT_(card, 2, "1err%04x", rc); 321 /* fall back once more: */ 322 } 323 324 /* some devices don't support a custom MAC address: */ 325 if (IS_OSM(card) || IS_OSX(card)) 326 return (rc) ? rc : -EADDRNOTAVAIL; 327 eth_hw_addr_random(card->dev); 328 329 out: 330 QETH_CARD_HEX(card, 2, card->dev->dev_addr, card->dev->addr_len); 331 return 0; 332 } 333 334 static void qeth_l2_register_dev_addr(struct qeth_card *card) 335 { 336 if (!is_valid_ether_addr(card->dev->dev_addr)) 337 qeth_l2_request_initial_mac(card); 338 339 if (!IS_OSN(card) && !qeth_l2_send_setmac(card, card->dev->dev_addr)) 340 card->info.dev_addr_is_registered = 1; 341 else 342 card->info.dev_addr_is_registered = 0; 343 } 344 345 static int qeth_l2_validate_addr(struct net_device *dev) 346 { 347 struct qeth_card *card = dev->ml_priv; 348 349 if (card->info.dev_addr_is_registered) 350 return eth_validate_addr(dev); 351 352 QETH_CARD_TEXT(card, 4, "nomacadr"); 353 return -EPERM; 354 } 355 356 static int qeth_l2_set_mac_address(struct net_device *dev, void *p) 357 { 358 struct sockaddr *addr = p; 359 struct qeth_card *card = dev->ml_priv; 360 u8 old_addr[ETH_ALEN]; 361 int rc = 0; 362 363 QETH_CARD_TEXT(card, 3, "setmac"); 364 365 if (IS_OSM(card) || IS_OSX(card)) { 366 QETH_CARD_TEXT(card, 3, "setmcTYP"); 367 return -EOPNOTSUPP; 368 } 369 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN); 370 if (!is_valid_ether_addr(addr->sa_data)) 371 return -EADDRNOTAVAIL; 372 373 /* don't register the same address twice */ 374 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) && 375 card->info.dev_addr_is_registered) 376 return 0; 377 378 /* add the new address, switch over, drop the old */ 379 rc = qeth_l2_send_setmac(card, addr->sa_data); 380 if (rc) 381 return rc; 382 ether_addr_copy(old_addr, dev->dev_addr); 383 ether_addr_copy(dev->dev_addr, addr->sa_data); 384 385 if (card->info.dev_addr_is_registered) 386 qeth_l2_remove_mac(card, old_addr); 387 card->info.dev_addr_is_registered = 1; 388 return 0; 389 } 390 391 static void qeth_l2_promisc_to_bridge(struct qeth_card *card, bool enable) 392 { 393 int role; 394 int rc; 395 396 QETH_CARD_TEXT(card, 3, "pmisc2br"); 397 398 if (enable) { 399 if (card->options.sbp.reflect_promisc_primary) 400 role = QETH_SBP_ROLE_PRIMARY; 401 else 402 role = QETH_SBP_ROLE_SECONDARY; 403 } else 404 role = QETH_SBP_ROLE_NONE; 405 406 rc = qeth_bridgeport_setrole(card, role); 407 QETH_CARD_TEXT_(card, 2, "bpm%c%04x", enable ? '+' : '-', rc); 408 if (!rc) { 409 card->options.sbp.role = role; 410 card->info.promisc_mode = enable; 411 } 412 } 413 414 static void qeth_l2_set_promisc_mode(struct qeth_card *card) 415 { 416 bool enable = card->dev->flags & IFF_PROMISC; 417 418 if (card->info.promisc_mode == enable) 419 return; 420 421 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) { 422 qeth_setadp_promisc_mode(card, enable); 423 } else { 424 mutex_lock(&card->sbp_lock); 425 if (card->options.sbp.reflect_promisc) 426 qeth_l2_promisc_to_bridge(card, enable); 427 mutex_unlock(&card->sbp_lock); 428 } 429 } 430 431 /* New MAC address is added to the hash table and marked to be written on card 432 * only if there is not in the hash table storage already 433 * 434 */ 435 static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha) 436 { 437 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2])); 438 struct qeth_mac *mac; 439 440 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) { 441 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) { 442 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 443 return; 444 } 445 } 446 447 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC); 448 if (!mac) 449 return; 450 451 ether_addr_copy(mac->mac_addr, ha->addr); 452 mac->disp_flag = QETH_DISP_ADDR_ADD; 453 454 hash_add(card->mac_htable, &mac->hnode, mac_hash); 455 } 456 457 static void qeth_l2_rx_mode_work(struct work_struct *work) 458 { 459 struct qeth_card *card = container_of(work, struct qeth_card, 460 rx_mode_work); 461 struct net_device *dev = card->dev; 462 struct netdev_hw_addr *ha; 463 struct qeth_mac *mac; 464 struct hlist_node *tmp; 465 int i; 466 int rc; 467 468 QETH_CARD_TEXT(card, 3, "setmulti"); 469 470 netif_addr_lock_bh(dev); 471 netdev_for_each_mc_addr(ha, dev) 472 qeth_l2_add_mac(card, ha); 473 netdev_for_each_uc_addr(ha, dev) 474 qeth_l2_add_mac(card, ha); 475 netif_addr_unlock_bh(dev); 476 477 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { 478 switch (mac->disp_flag) { 479 case QETH_DISP_ADDR_DELETE: 480 qeth_l2_remove_mac(card, mac->mac_addr); 481 hash_del(&mac->hnode); 482 kfree(mac); 483 break; 484 case QETH_DISP_ADDR_ADD: 485 rc = qeth_l2_write_mac(card, mac->mac_addr); 486 if (rc) { 487 hash_del(&mac->hnode); 488 kfree(mac); 489 break; 490 } 491 /* fall through */ 492 default: 493 /* for next call to set_rx_mode(): */ 494 mac->disp_flag = QETH_DISP_ADDR_DELETE; 495 } 496 } 497 498 qeth_l2_set_promisc_mode(card); 499 } 500 501 static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb, 502 struct qeth_qdio_out_q *queue) 503 { 504 gfp_t gfp = GFP_ATOMIC | (skb_pfmemalloc(skb) ? __GFP_MEMALLOC : 0); 505 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data; 506 addr_t end = (addr_t)(skb->data + sizeof(*hdr)); 507 addr_t start = (addr_t)skb->data; 508 unsigned int elements = 0; 509 unsigned int hd_len = 0; 510 int rc; 511 512 if (skb->protocol == htons(ETH_P_IPV6)) 513 return -EPROTONOSUPPORT; 514 515 if (qeth_get_elements_for_range(start, end) > 1) { 516 /* Misaligned HW header, move it to its own buffer element. */ 517 hdr = kmem_cache_alloc(qeth_core_header_cache, gfp); 518 if (!hdr) 519 return -ENOMEM; 520 hd_len = sizeof(*hdr); 521 skb_copy_from_linear_data(skb, (char *)hdr, hd_len); 522 elements++; 523 } 524 525 elements += qeth_count_elements(skb, hd_len); 526 if (elements > queue->max_elements) { 527 rc = -E2BIG; 528 goto out; 529 } 530 531 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len, 532 elements); 533 out: 534 if (rc && hd_len) 535 kmem_cache_free(qeth_core_header_cache, hdr); 536 return rc; 537 } 538 539 static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb, 540 struct net_device *dev) 541 { 542 struct qeth_card *card = dev->ml_priv; 543 u16 txq = skb_get_queue_mapping(skb); 544 struct qeth_qdio_out_q *queue; 545 int rc; 546 547 if (!skb_is_gso(skb)) 548 qdisc_skb_cb(skb)->pkt_len = skb->len; 549 if (IS_IQD(card)) 550 txq = qeth_iqd_translate_txq(dev, txq); 551 queue = card->qdio.out_qs[txq]; 552 553 if (IS_OSN(card)) 554 rc = qeth_l2_xmit_osn(card, skb, queue); 555 else 556 rc = qeth_xmit(card, skb, queue, qeth_get_ip_version(skb), 557 qeth_l2_fill_header); 558 559 if (!rc) 560 return NETDEV_TX_OK; 561 562 QETH_TXQ_STAT_INC(queue, tx_dropped); 563 kfree_skb(skb); 564 return NETDEV_TX_OK; 565 } 566 567 static u16 qeth_l2_select_queue(struct net_device *dev, struct sk_buff *skb, 568 struct net_device *sb_dev) 569 { 570 struct qeth_card *card = dev->ml_priv; 571 572 if (IS_IQD(card)) 573 return qeth_iqd_select_queue(dev, skb, 574 qeth_get_ether_cast_type(skb), 575 sb_dev); 576 577 return IS_VM_NIC(card) ? netdev_pick_tx(dev, skb, sb_dev) : 578 qeth_get_priority_queue(card, skb); 579 } 580 581 static const struct device_type qeth_l2_devtype = { 582 .name = "qeth_layer2", 583 .groups = qeth_l2_attr_groups, 584 }; 585 586 static int qeth_l2_probe_device(struct ccwgroup_device *gdev) 587 { 588 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 589 int rc; 590 591 if (IS_OSN(card)) 592 dev_notice(&gdev->dev, "OSN support will be dropped in 2021\n"); 593 594 qeth_l2_vnicc_set_defaults(card); 595 mutex_init(&card->sbp_lock); 596 597 if (gdev->dev.type == &qeth_generic_devtype) { 598 rc = qeth_l2_create_device_attributes(&gdev->dev); 599 if (rc) 600 return rc; 601 } 602 603 hash_init(card->mac_htable); 604 INIT_WORK(&card->rx_mode_work, qeth_l2_rx_mode_work); 605 return 0; 606 } 607 608 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev) 609 { 610 struct qeth_card *card = dev_get_drvdata(&cgdev->dev); 611 612 if (cgdev->dev.type == &qeth_generic_devtype) 613 qeth_l2_remove_device_attributes(&cgdev->dev); 614 qeth_set_allowed_threads(card, 0, 1); 615 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); 616 617 if (cgdev->state == CCWGROUP_ONLINE) 618 qeth_set_offline(card, false); 619 620 cancel_work_sync(&card->close_dev_work); 621 if (card->dev->reg_state == NETREG_REGISTERED) 622 unregister_netdev(card->dev); 623 } 624 625 static void qeth_l2_set_rx_mode(struct net_device *dev) 626 { 627 struct qeth_card *card = dev->ml_priv; 628 629 schedule_work(&card->rx_mode_work); 630 } 631 632 static const struct net_device_ops qeth_l2_netdev_ops = { 633 .ndo_open = qeth_open, 634 .ndo_stop = qeth_stop, 635 .ndo_get_stats64 = qeth_get_stats64, 636 .ndo_start_xmit = qeth_l2_hard_start_xmit, 637 .ndo_features_check = qeth_features_check, 638 .ndo_select_queue = qeth_l2_select_queue, 639 .ndo_validate_addr = qeth_l2_validate_addr, 640 .ndo_set_rx_mode = qeth_l2_set_rx_mode, 641 .ndo_do_ioctl = qeth_do_ioctl, 642 .ndo_set_mac_address = qeth_l2_set_mac_address, 643 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid, 644 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid, 645 .ndo_tx_timeout = qeth_tx_timeout, 646 .ndo_fix_features = qeth_fix_features, 647 .ndo_set_features = qeth_set_features 648 }; 649 650 static const struct net_device_ops qeth_osn_netdev_ops = { 651 .ndo_open = qeth_open, 652 .ndo_stop = qeth_stop, 653 .ndo_get_stats64 = qeth_get_stats64, 654 .ndo_start_xmit = qeth_l2_hard_start_xmit, 655 .ndo_validate_addr = eth_validate_addr, 656 .ndo_tx_timeout = qeth_tx_timeout, 657 }; 658 659 static int qeth_l2_setup_netdev(struct qeth_card *card) 660 { 661 int rc; 662 663 if (IS_OSN(card)) { 664 card->dev->netdev_ops = &qeth_osn_netdev_ops; 665 card->dev->flags |= IFF_NOARP; 666 goto add_napi; 667 } 668 669 rc = qeth_setup_netdev(card); 670 if (rc) 671 return rc; 672 673 card->dev->needed_headroom = sizeof(struct qeth_hdr); 674 card->dev->netdev_ops = &qeth_l2_netdev_ops; 675 card->dev->priv_flags |= IFF_UNICAST_FLT; 676 677 if (IS_OSM(card)) { 678 card->dev->features |= NETIF_F_VLAN_CHALLENGED; 679 } else { 680 if (!IS_VM_NIC(card)) 681 card->dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER; 682 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; 683 } 684 685 if (IS_OSD(card) && !IS_VM_NIC(card)) { 686 card->dev->features |= NETIF_F_SG; 687 /* OSA 3S and earlier has no RX/TX support */ 688 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) { 689 card->dev->hw_features |= NETIF_F_IP_CSUM; 690 card->dev->vlan_features |= NETIF_F_IP_CSUM; 691 } 692 } 693 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) { 694 card->dev->hw_features |= NETIF_F_IPV6_CSUM; 695 card->dev->vlan_features |= NETIF_F_IPV6_CSUM; 696 } 697 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) || 698 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) { 699 card->dev->hw_features |= NETIF_F_RXCSUM; 700 card->dev->vlan_features |= NETIF_F_RXCSUM; 701 } 702 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) { 703 card->dev->hw_features |= NETIF_F_TSO; 704 card->dev->vlan_features |= NETIF_F_TSO; 705 } 706 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) { 707 card->dev->hw_features |= NETIF_F_TSO6; 708 card->dev->vlan_features |= NETIF_F_TSO6; 709 } 710 711 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) { 712 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso); 713 netif_keep_dst(card->dev); 714 netif_set_gso_max_size(card->dev, 715 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)); 716 } 717 718 add_napi: 719 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); 720 return register_netdev(card->dev); 721 } 722 723 static void qeth_l2_trace_features(struct qeth_card *card) 724 { 725 /* Set BridgePort features */ 726 QETH_CARD_TEXT(card, 2, "featuSBP"); 727 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs, 728 sizeof(card->options.sbp.supported_funcs)); 729 /* VNIC Characteristics features */ 730 QETH_CARD_TEXT(card, 2, "feaVNICC"); 731 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars, 732 sizeof(card->options.vnicc.sup_chars)); 733 } 734 735 static void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card) 736 { 737 if (!card->options.sbp.reflect_promisc && 738 card->options.sbp.role != QETH_SBP_ROLE_NONE) { 739 /* Conditional to avoid spurious error messages */ 740 qeth_bridgeport_setrole(card, card->options.sbp.role); 741 /* Let the callback function refresh the stored role value. */ 742 qeth_bridgeport_query_ports(card, &card->options.sbp.role, 743 NULL); 744 } 745 if (card->options.sbp.hostnotification) { 746 if (qeth_bridgeport_an_set(card, 1)) 747 card->options.sbp.hostnotification = 0; 748 } else { 749 qeth_bridgeport_an_set(card, 0); 750 } 751 } 752 753 static int qeth_l2_set_online(struct qeth_card *card) 754 { 755 struct ccwgroup_device *gdev = card->gdev; 756 struct net_device *dev = card->dev; 757 int rc = 0; 758 bool carrier_ok; 759 760 rc = qeth_core_hardsetup_card(card, &carrier_ok); 761 if (rc) { 762 QETH_CARD_TEXT_(card, 2, "2err%04x", rc); 763 rc = -ENODEV; 764 goto out_remove; 765 } 766 767 mutex_lock(&card->sbp_lock); 768 qeth_bridgeport_query_support(card); 769 if (card->options.sbp.supported_funcs) { 770 qeth_l2_setup_bridgeport_attrs(card); 771 dev_info(&card->gdev->dev, 772 "The device represents a Bridge Capable Port\n"); 773 } 774 mutex_unlock(&card->sbp_lock); 775 776 qeth_l2_register_dev_addr(card); 777 778 /* for the rx_bcast characteristic, init VNICC after setmac */ 779 qeth_l2_vnicc_init(card); 780 781 qeth_trace_features(card); 782 qeth_l2_trace_features(card); 783 784 qeth_print_status_message(card); 785 786 /* softsetup */ 787 QETH_CARD_TEXT(card, 2, "softsetp"); 788 789 card->state = CARD_STATE_SOFTSETUP; 790 791 qeth_set_allowed_threads(card, 0xffffffff, 0); 792 793 if (dev->reg_state != NETREG_REGISTERED) { 794 rc = qeth_l2_setup_netdev(card); 795 if (rc) 796 goto out_remove; 797 798 if (carrier_ok) 799 netif_carrier_on(dev); 800 } else { 801 rtnl_lock(); 802 if (carrier_ok) 803 netif_carrier_on(dev); 804 else 805 netif_carrier_off(dev); 806 807 netif_device_attach(dev); 808 qeth_enable_hw_features(dev); 809 810 if (card->info.open_when_online) { 811 card->info.open_when_online = 0; 812 dev_open(dev, NULL); 813 } 814 rtnl_unlock(); 815 } 816 /* let user_space know that device is online */ 817 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); 818 return 0; 819 820 out_remove: 821 qeth_l2_stop_card(card); 822 qeth_stop_channel(&card->data); 823 qeth_stop_channel(&card->write); 824 qeth_stop_channel(&card->read); 825 qdio_free(CARD_DDEV(card)); 826 return rc; 827 } 828 829 static void qeth_l2_set_offline(struct qeth_card *card) 830 { 831 qeth_l2_stop_card(card); 832 } 833 834 static int __init qeth_l2_init(void) 835 { 836 pr_info("register layer 2 discipline\n"); 837 return 0; 838 } 839 840 static void __exit qeth_l2_exit(void) 841 { 842 pr_info("unregister layer 2 discipline\n"); 843 } 844 845 /* Returns zero if the command is successfully "consumed" */ 846 static int qeth_l2_control_event(struct qeth_card *card, 847 struct qeth_ipa_cmd *cmd) 848 { 849 switch (cmd->hdr.command) { 850 case IPA_CMD_SETBRIDGEPORT_OSA: 851 case IPA_CMD_SETBRIDGEPORT_IQD: 852 if (cmd->data.sbp.hdr.command_code == 853 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) { 854 qeth_bridge_state_change(card, cmd); 855 return 0; 856 } else 857 return 1; 858 case IPA_CMD_ADDRESS_CHANGE_NOTIF: 859 qeth_bridge_host_event(card, cmd); 860 return 0; 861 default: 862 return 1; 863 } 864 } 865 866 struct qeth_discipline qeth_l2_discipline = { 867 .devtype = &qeth_l2_devtype, 868 .setup = qeth_l2_probe_device, 869 .remove = qeth_l2_remove_device, 870 .set_online = qeth_l2_set_online, 871 .set_offline = qeth_l2_set_offline, 872 .do_ioctl = NULL, 873 .control_event_handler = qeth_l2_control_event, 874 }; 875 EXPORT_SYMBOL_GPL(qeth_l2_discipline); 876 877 #ifdef CONFIG_QETH_OSN 878 static void qeth_osn_assist_cb(struct qeth_card *card, 879 struct qeth_cmd_buffer *iob, 880 unsigned int data_length) 881 { 882 qeth_notify_cmd(iob, 0); 883 qeth_put_cmd(iob); 884 } 885 886 int qeth_osn_assist(struct net_device *dev, void *data, int data_len) 887 { 888 struct qeth_cmd_buffer *iob; 889 struct qeth_card *card; 890 891 if (data_len < 0) 892 return -EINVAL; 893 if (!dev) 894 return -ENODEV; 895 card = dev->ml_priv; 896 if (!card) 897 return -ENODEV; 898 QETH_CARD_TEXT(card, 2, "osnsdmc"); 899 if (!qeth_card_hw_is_reachable(card)) 900 return -ENODEV; 901 902 iob = qeth_alloc_cmd(&card->write, IPA_PDU_HEADER_SIZE + data_len, 1, 903 QETH_IPA_TIMEOUT); 904 if (!iob) 905 return -ENOMEM; 906 907 qeth_prepare_ipa_cmd(card, iob, (u16) data_len, NULL); 908 909 memcpy(__ipa_cmd(iob), data, data_len); 910 iob->callback = qeth_osn_assist_cb; 911 return qeth_send_ipa_cmd(card, iob, NULL, NULL); 912 } 913 EXPORT_SYMBOL(qeth_osn_assist); 914 915 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev, 916 int (*assist_cb)(struct net_device *, void *), 917 int (*data_cb)(struct sk_buff *)) 918 { 919 struct qeth_card *card; 920 char bus_id[16]; 921 u16 devno; 922 923 memcpy(&devno, read_dev_no, 2); 924 sprintf(bus_id, "0.0.%04x", devno); 925 card = qeth_get_card_by_busid(bus_id); 926 if (!card || !IS_OSN(card)) 927 return -ENODEV; 928 *dev = card->dev; 929 930 QETH_CARD_TEXT(card, 2, "osnreg"); 931 if ((assist_cb == NULL) || (data_cb == NULL)) 932 return -EINVAL; 933 card->osn_info.assist_cb = assist_cb; 934 card->osn_info.data_cb = data_cb; 935 return 0; 936 } 937 EXPORT_SYMBOL(qeth_osn_register); 938 939 void qeth_osn_deregister(struct net_device *dev) 940 { 941 struct qeth_card *card; 942 943 if (!dev) 944 return; 945 card = dev->ml_priv; 946 if (!card) 947 return; 948 QETH_CARD_TEXT(card, 2, "osndereg"); 949 card->osn_info.assist_cb = NULL; 950 card->osn_info.data_cb = NULL; 951 return; 952 } 953 EXPORT_SYMBOL(qeth_osn_deregister); 954 #endif 955 956 /* SETBRIDGEPORT support, async notifications */ 957 958 enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset}; 959 960 /** 961 * qeth_bridge_emit_host_event() - bridgeport address change notification 962 * @card: qeth_card structure pointer, for udev events. 963 * @evtype: "normal" register/unregister, or abort, or reset. For abort 964 * and reset token and addr_lnid are unused and may be NULL. 965 * @code: event bitmask: high order bit 0x80 value 1 means removal of an 966 * object, 0 - addition of an object. 967 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC. 968 * @token: "network token" structure identifying physical address of the port. 969 * @addr_lnid: pointer to structure with MAC address and VLAN ID. 970 * 971 * This function is called when registrations and deregistrations are 972 * reported by the hardware, and also when notifications are enabled - 973 * for all currently registered addresses. 974 */ 975 static void qeth_bridge_emit_host_event(struct qeth_card *card, 976 enum qeth_an_event_type evtype, 977 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid) 978 { 979 char str[7][32]; 980 char *env[8]; 981 int i = 0; 982 983 switch (evtype) { 984 case anev_reg_unreg: 985 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s", 986 (code & IPA_ADDR_CHANGE_CODE_REMOVAL) 987 ? "deregister" : "register"); 988 env[i] = str[i]; i++; 989 if (code & IPA_ADDR_CHANGE_CODE_VLANID) { 990 snprintf(str[i], sizeof(str[i]), "VLAN=%d", 991 addr_lnid->lnid); 992 env[i] = str[i]; i++; 993 } 994 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) { 995 snprintf(str[i], sizeof(str[i]), "MAC=%pM", 996 addr_lnid->mac); 997 env[i] = str[i]; i++; 998 } 999 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x", 1000 token->cssid, token->ssid, token->devnum); 1001 env[i] = str[i]; i++; 1002 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid); 1003 env[i] = str[i]; i++; 1004 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x", 1005 token->chpid); 1006 env[i] = str[i]; i++; 1007 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid); 1008 env[i] = str[i]; i++; 1009 break; 1010 case anev_abort: 1011 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort"); 1012 env[i] = str[i]; i++; 1013 break; 1014 case anev_reset: 1015 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset"); 1016 env[i] = str[i]; i++; 1017 break; 1018 } 1019 env[i] = NULL; 1020 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env); 1021 } 1022 1023 struct qeth_bridge_state_data { 1024 struct work_struct worker; 1025 struct qeth_card *card; 1026 struct qeth_sbp_state_change qports; 1027 }; 1028 1029 static void qeth_bridge_state_change_worker(struct work_struct *work) 1030 { 1031 struct qeth_bridge_state_data *data = 1032 container_of(work, struct qeth_bridge_state_data, worker); 1033 /* We are only interested in the first entry - local port */ 1034 struct qeth_sbp_port_entry *entry = &data->qports.entry[0]; 1035 char env_locrem[32]; 1036 char env_role[32]; 1037 char env_state[32]; 1038 char *env[] = { 1039 env_locrem, 1040 env_role, 1041 env_state, 1042 NULL 1043 }; 1044 1045 /* Role should not change by itself, but if it did, */ 1046 /* information from the hardware is authoritative. */ 1047 mutex_lock(&data->card->sbp_lock); 1048 data->card->options.sbp.role = entry->role; 1049 mutex_unlock(&data->card->sbp_lock); 1050 1051 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange"); 1052 snprintf(env_role, sizeof(env_role), "ROLE=%s", 1053 (entry->role == QETH_SBP_ROLE_NONE) ? "none" : 1054 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" : 1055 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" : 1056 "<INVALID>"); 1057 snprintf(env_state, sizeof(env_state), "STATE=%s", 1058 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" : 1059 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" : 1060 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" : 1061 "<INVALID>"); 1062 kobject_uevent_env(&data->card->gdev->dev.kobj, 1063 KOBJ_CHANGE, env); 1064 kfree(data); 1065 } 1066 1067 static void qeth_bridge_state_change(struct qeth_card *card, 1068 struct qeth_ipa_cmd *cmd) 1069 { 1070 struct qeth_sbp_state_change *qports = 1071 &cmd->data.sbp.data.state_change; 1072 struct qeth_bridge_state_data *data; 1073 int extrasize; 1074 1075 QETH_CARD_TEXT(card, 2, "brstchng"); 1076 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { 1077 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length); 1078 return; 1079 } 1080 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries; 1081 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize, 1082 GFP_ATOMIC); 1083 if (!data) { 1084 QETH_CARD_TEXT(card, 2, "BPSalloc"); 1085 return; 1086 } 1087 INIT_WORK(&data->worker, qeth_bridge_state_change_worker); 1088 data->card = card; 1089 memcpy(&data->qports, qports, 1090 sizeof(struct qeth_sbp_state_change) + extrasize); 1091 queue_work(card->event_wq, &data->worker); 1092 } 1093 1094 struct qeth_bridge_host_data { 1095 struct work_struct worker; 1096 struct qeth_card *card; 1097 struct qeth_ipacmd_addr_change hostevs; 1098 }; 1099 1100 static void qeth_bridge_host_event_worker(struct work_struct *work) 1101 { 1102 struct qeth_bridge_host_data *data = 1103 container_of(work, struct qeth_bridge_host_data, worker); 1104 int i; 1105 1106 if (data->hostevs.lost_event_mask) { 1107 dev_info(&data->card->gdev->dev, 1108 "Address notification from the Bridge Port stopped %s (%s)\n", 1109 data->card->dev->name, 1110 (data->hostevs.lost_event_mask == 0x01) 1111 ? "Overflow" 1112 : (data->hostevs.lost_event_mask == 0x02) 1113 ? "Bridge port state change" 1114 : "Unknown reason"); 1115 mutex_lock(&data->card->sbp_lock); 1116 data->card->options.sbp.hostnotification = 0; 1117 mutex_unlock(&data->card->sbp_lock); 1118 qeth_bridge_emit_host_event(data->card, anev_abort, 1119 0, NULL, NULL); 1120 } else 1121 for (i = 0; i < data->hostevs.num_entries; i++) { 1122 struct qeth_ipacmd_addr_change_entry *entry = 1123 &data->hostevs.entry[i]; 1124 qeth_bridge_emit_host_event(data->card, 1125 anev_reg_unreg, 1126 entry->change_code, 1127 &entry->token, &entry->addr_lnid); 1128 } 1129 kfree(data); 1130 } 1131 1132 static void qeth_bridge_host_event(struct qeth_card *card, 1133 struct qeth_ipa_cmd *cmd) 1134 { 1135 struct qeth_ipacmd_addr_change *hostevs = 1136 &cmd->data.addrchange; 1137 struct qeth_bridge_host_data *data; 1138 int extrasize; 1139 1140 QETH_CARD_TEXT(card, 2, "brhostev"); 1141 if (cmd->hdr.return_code != 0x0000) { 1142 if (cmd->hdr.return_code == 0x0010) { 1143 if (hostevs->lost_event_mask == 0x00) 1144 hostevs->lost_event_mask = 0xff; 1145 } else { 1146 QETH_CARD_TEXT_(card, 2, "BPHe%04x", 1147 cmd->hdr.return_code); 1148 return; 1149 } 1150 } 1151 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) * 1152 hostevs->num_entries; 1153 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize, 1154 GFP_ATOMIC); 1155 if (!data) { 1156 QETH_CARD_TEXT(card, 2, "BPHalloc"); 1157 return; 1158 } 1159 INIT_WORK(&data->worker, qeth_bridge_host_event_worker); 1160 data->card = card; 1161 memcpy(&data->hostevs, hostevs, 1162 sizeof(struct qeth_ipacmd_addr_change) + extrasize); 1163 queue_work(card->event_wq, &data->worker); 1164 } 1165 1166 /* SETBRIDGEPORT support; sending commands */ 1167 1168 struct _qeth_sbp_cbctl { 1169 union { 1170 u32 supported; 1171 struct { 1172 enum qeth_sbp_roles *role; 1173 enum qeth_sbp_states *state; 1174 } qports; 1175 } data; 1176 }; 1177 1178 static int qeth_bridgeport_makerc(struct qeth_card *card, 1179 struct qeth_ipa_cmd *cmd) 1180 { 1181 struct qeth_ipacmd_setbridgeport *sbp = &cmd->data.sbp; 1182 enum qeth_ipa_sbp_cmd setcmd = sbp->hdr.command_code; 1183 u16 ipa_rc = cmd->hdr.return_code; 1184 u16 sbp_rc = sbp->hdr.return_code; 1185 int rc; 1186 1187 if (ipa_rc == IPA_RC_SUCCESS && sbp_rc == IPA_RC_SUCCESS) 1188 return 0; 1189 1190 if ((IS_IQD(card) && ipa_rc == IPA_RC_SUCCESS) || 1191 (!IS_IQD(card) && ipa_rc == sbp_rc)) { 1192 switch (sbp_rc) { 1193 case IPA_RC_SUCCESS: 1194 rc = 0; 1195 break; 1196 case IPA_RC_L2_UNSUPPORTED_CMD: 1197 case IPA_RC_UNSUPPORTED_COMMAND: 1198 rc = -EOPNOTSUPP; 1199 break; 1200 case IPA_RC_SBP_OSA_NOT_CONFIGURED: 1201 case IPA_RC_SBP_IQD_NOT_CONFIGURED: 1202 rc = -ENODEV; /* maybe not the best code here? */ 1203 dev_err(&card->gdev->dev, 1204 "The device is not configured as a Bridge Port\n"); 1205 break; 1206 case IPA_RC_SBP_OSA_OS_MISMATCH: 1207 case IPA_RC_SBP_IQD_OS_MISMATCH: 1208 rc = -EPERM; 1209 dev_err(&card->gdev->dev, 1210 "A Bridge Port is already configured by a different operating system\n"); 1211 break; 1212 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY: 1213 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY: 1214 switch (setcmd) { 1215 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT: 1216 rc = -EEXIST; 1217 dev_err(&card->gdev->dev, 1218 "The LAN already has a primary Bridge Port\n"); 1219 break; 1220 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT: 1221 rc = -EBUSY; 1222 dev_err(&card->gdev->dev, 1223 "The device is already a primary Bridge Port\n"); 1224 break; 1225 default: 1226 rc = -EIO; 1227 } 1228 break; 1229 case IPA_RC_SBP_OSA_CURRENT_SECOND: 1230 case IPA_RC_SBP_IQD_CURRENT_SECOND: 1231 rc = -EBUSY; 1232 dev_err(&card->gdev->dev, 1233 "The device is already a secondary Bridge Port\n"); 1234 break; 1235 case IPA_RC_SBP_OSA_LIMIT_SECOND: 1236 case IPA_RC_SBP_IQD_LIMIT_SECOND: 1237 rc = -EEXIST; 1238 dev_err(&card->gdev->dev, 1239 "The LAN cannot have more secondary Bridge Ports\n"); 1240 break; 1241 case IPA_RC_SBP_OSA_CURRENT_PRIMARY: 1242 case IPA_RC_SBP_IQD_CURRENT_PRIMARY: 1243 rc = -EBUSY; 1244 dev_err(&card->gdev->dev, 1245 "The device is already a primary Bridge Port\n"); 1246 break; 1247 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN: 1248 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN: 1249 rc = -EACCES; 1250 dev_err(&card->gdev->dev, 1251 "The device is not authorized to be a Bridge Port\n"); 1252 break; 1253 default: 1254 rc = -EIO; 1255 } 1256 } else { 1257 switch (ipa_rc) { 1258 case IPA_RC_NOTSUPP: 1259 rc = -EOPNOTSUPP; 1260 break; 1261 case IPA_RC_UNSUPPORTED_COMMAND: 1262 rc = -EOPNOTSUPP; 1263 break; 1264 default: 1265 rc = -EIO; 1266 } 1267 } 1268 1269 if (rc) { 1270 QETH_CARD_TEXT_(card, 2, "SBPi%04x", ipa_rc); 1271 QETH_CARD_TEXT_(card, 2, "SBPc%04x", sbp_rc); 1272 } 1273 return rc; 1274 } 1275 1276 static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card, 1277 enum qeth_ipa_sbp_cmd sbp_cmd, 1278 unsigned int data_length) 1279 { 1280 enum qeth_ipa_cmds ipa_cmd = IS_IQD(card) ? IPA_CMD_SETBRIDGEPORT_IQD : 1281 IPA_CMD_SETBRIDGEPORT_OSA; 1282 struct qeth_ipacmd_sbp_hdr *hdr; 1283 struct qeth_cmd_buffer *iob; 1284 1285 iob = qeth_ipa_alloc_cmd(card, ipa_cmd, QETH_PROT_NONE, 1286 data_length + 1287 offsetof(struct qeth_ipacmd_setbridgeport, 1288 data)); 1289 if (!iob) 1290 return iob; 1291 1292 hdr = &__ipa_cmd(iob)->data.sbp.hdr; 1293 hdr->cmdlength = sizeof(*hdr) + data_length; 1294 hdr->command_code = sbp_cmd; 1295 hdr->used_total = 1; 1296 hdr->seq_no = 1; 1297 return iob; 1298 } 1299 1300 static int qeth_bridgeport_query_support_cb(struct qeth_card *card, 1301 struct qeth_reply *reply, unsigned long data) 1302 { 1303 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1304 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; 1305 int rc; 1306 1307 QETH_CARD_TEXT(card, 2, "brqsupcb"); 1308 rc = qeth_bridgeport_makerc(card, cmd); 1309 if (rc) 1310 return rc; 1311 1312 cbctl->data.supported = 1313 cmd->data.sbp.data.query_cmds_supp.supported_cmds; 1314 return 0; 1315 } 1316 1317 /** 1318 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions. 1319 * @card: qeth_card structure pointer. 1320 * 1321 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card 1322 * strucutre: card->options.sbp.supported_funcs. 1323 */ 1324 static void qeth_bridgeport_query_support(struct qeth_card *card) 1325 { 1326 struct qeth_cmd_buffer *iob; 1327 struct _qeth_sbp_cbctl cbctl; 1328 1329 QETH_CARD_TEXT(card, 2, "brqsuppo"); 1330 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED, 1331 SBP_DATA_SIZEOF(query_cmds_supp)); 1332 if (!iob) 1333 return; 1334 1335 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb, 1336 &cbctl)) { 1337 card->options.sbp.role = QETH_SBP_ROLE_NONE; 1338 card->options.sbp.supported_funcs = 0; 1339 return; 1340 } 1341 card->options.sbp.supported_funcs = cbctl.data.supported; 1342 } 1343 1344 static int qeth_bridgeport_query_ports_cb(struct qeth_card *card, 1345 struct qeth_reply *reply, unsigned long data) 1346 { 1347 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1348 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports; 1349 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; 1350 int rc; 1351 1352 QETH_CARD_TEXT(card, 2, "brqprtcb"); 1353 rc = qeth_bridgeport_makerc(card, cmd); 1354 if (rc) 1355 return rc; 1356 1357 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { 1358 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length); 1359 return -EINVAL; 1360 } 1361 /* first entry contains the state of the local port */ 1362 if (qports->num_entries > 0) { 1363 if (cbctl->data.qports.role) 1364 *cbctl->data.qports.role = qports->entry[0].role; 1365 if (cbctl->data.qports.state) 1366 *cbctl->data.qports.state = qports->entry[0].state; 1367 } 1368 return 0; 1369 } 1370 1371 /** 1372 * qeth_bridgeport_query_ports() - query local bridgeport status. 1373 * @card: qeth_card structure pointer. 1374 * @role: Role of the port: 0-none, 1-primary, 2-secondary. 1375 * @state: State of the port: 0-inactive, 1-standby, 2-active. 1376 * 1377 * Returns negative errno-compatible error indication or 0 on success. 1378 * 1379 * 'role' and 'state' are not updated in case of hardware operation failure. 1380 */ 1381 int qeth_bridgeport_query_ports(struct qeth_card *card, 1382 enum qeth_sbp_roles *role, enum qeth_sbp_states *state) 1383 { 1384 struct qeth_cmd_buffer *iob; 1385 struct _qeth_sbp_cbctl cbctl = { 1386 .data = { 1387 .qports = { 1388 .role = role, 1389 .state = state, 1390 }, 1391 }, 1392 }; 1393 1394 QETH_CARD_TEXT(card, 2, "brqports"); 1395 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS)) 1396 return -EOPNOTSUPP; 1397 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0); 1398 if (!iob) 1399 return -ENOMEM; 1400 1401 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb, 1402 &cbctl); 1403 } 1404 1405 static int qeth_bridgeport_set_cb(struct qeth_card *card, 1406 struct qeth_reply *reply, unsigned long data) 1407 { 1408 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data; 1409 1410 QETH_CARD_TEXT(card, 2, "brsetrcb"); 1411 return qeth_bridgeport_makerc(card, cmd); 1412 } 1413 1414 /** 1415 * qeth_bridgeport_setrole() - Assign primary role to the port. 1416 * @card: qeth_card structure pointer. 1417 * @role: Role to assign. 1418 * 1419 * Returns negative errno-compatible error indication or 0 on success. 1420 */ 1421 int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role) 1422 { 1423 struct qeth_cmd_buffer *iob; 1424 enum qeth_ipa_sbp_cmd setcmd; 1425 unsigned int cmdlength = 0; 1426 1427 QETH_CARD_TEXT(card, 2, "brsetrol"); 1428 switch (role) { 1429 case QETH_SBP_ROLE_NONE: 1430 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE; 1431 break; 1432 case QETH_SBP_ROLE_PRIMARY: 1433 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT; 1434 cmdlength = SBP_DATA_SIZEOF(set_primary); 1435 break; 1436 case QETH_SBP_ROLE_SECONDARY: 1437 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT; 1438 break; 1439 default: 1440 return -EINVAL; 1441 } 1442 if (!(card->options.sbp.supported_funcs & setcmd)) 1443 return -EOPNOTSUPP; 1444 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength); 1445 if (!iob) 1446 return -ENOMEM; 1447 1448 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, NULL); 1449 } 1450 1451 /** 1452 * qeth_anset_makerc() - derive "traditional" error from hardware codes. 1453 * @card: qeth_card structure pointer, for debug messages. 1454 * 1455 * Returns negative errno-compatible error indication or 0 on success. 1456 */ 1457 static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response) 1458 { 1459 int rc; 1460 1461 if (pnso_rc == 0) 1462 switch (response) { 1463 case 0x0001: 1464 rc = 0; 1465 break; 1466 case 0x0004: 1467 case 0x0100: 1468 case 0x0106: 1469 rc = -EOPNOTSUPP; 1470 dev_err(&card->gdev->dev, 1471 "Setting address notification failed\n"); 1472 break; 1473 case 0x0107: 1474 rc = -EAGAIN; 1475 break; 1476 default: 1477 rc = -EIO; 1478 } 1479 else 1480 rc = -EIO; 1481 1482 if (rc) { 1483 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc); 1484 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response); 1485 } 1486 return rc; 1487 } 1488 1489 static void qeth_bridgeport_an_set_cb(void *priv, 1490 enum qdio_brinfo_entry_type type, void *entry) 1491 { 1492 struct qeth_card *card = (struct qeth_card *)priv; 1493 struct qdio_brinfo_entry_l2 *l2entry; 1494 u8 code; 1495 1496 if (type != l2_addr_lnid) { 1497 WARN_ON_ONCE(1); 1498 return; 1499 } 1500 1501 l2entry = (struct qdio_brinfo_entry_l2 *)entry; 1502 code = IPA_ADDR_CHANGE_CODE_MACADDR; 1503 if (l2entry->addr_lnid.lnid < VLAN_N_VID) 1504 code |= IPA_ADDR_CHANGE_CODE_VLANID; 1505 qeth_bridge_emit_host_event(card, anev_reg_unreg, code, 1506 (struct net_if_token *)&l2entry->nit, 1507 (struct mac_addr_lnid *)&l2entry->addr_lnid); 1508 } 1509 1510 /** 1511 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification 1512 * @card: qeth_card structure pointer. 1513 * @enable: 0 - disable, non-zero - enable notifications 1514 * 1515 * Returns negative errno-compatible error indication or 0 on success. 1516 * 1517 * On enable, emits a series of address notifications udev events for all 1518 * currently registered hosts. 1519 */ 1520 int qeth_bridgeport_an_set(struct qeth_card *card, int enable) 1521 { 1522 int rc; 1523 u16 response; 1524 struct ccw_device *ddev; 1525 struct subchannel_id schid; 1526 1527 if (!card->options.sbp.supported_funcs) 1528 return -EOPNOTSUPP; 1529 ddev = CARD_DDEV(card); 1530 ccw_device_get_schid(ddev, &schid); 1531 1532 if (enable) { 1533 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL); 1534 rc = qdio_pnso_brinfo(schid, 1, &response, 1535 qeth_bridgeport_an_set_cb, card); 1536 } else 1537 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL); 1538 return qeth_anset_makerc(card, rc, response); 1539 } 1540 1541 static bool qeth_bridgeport_is_in_use(struct qeth_card *card) 1542 { 1543 return (card->options.sbp.role || card->options.sbp.reflect_promisc || 1544 card->options.sbp.hostnotification); 1545 } 1546 1547 /* VNIC Characteristics support */ 1548 1549 /* handle VNICC IPA command return codes; convert to error codes */ 1550 static int qeth_l2_vnicc_makerc(struct qeth_card *card, u16 ipa_rc) 1551 { 1552 int rc; 1553 1554 switch (ipa_rc) { 1555 case IPA_RC_SUCCESS: 1556 return ipa_rc; 1557 case IPA_RC_L2_UNSUPPORTED_CMD: 1558 case IPA_RC_NOTSUPP: 1559 rc = -EOPNOTSUPP; 1560 break; 1561 case IPA_RC_VNICC_OOSEQ: 1562 rc = -EALREADY; 1563 break; 1564 case IPA_RC_VNICC_VNICBP: 1565 rc = -EBUSY; 1566 break; 1567 case IPA_RC_L2_ADDR_TABLE_FULL: 1568 rc = -ENOSPC; 1569 break; 1570 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: 1571 rc = -EACCES; 1572 break; 1573 default: 1574 rc = -EIO; 1575 } 1576 1577 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc); 1578 return rc; 1579 } 1580 1581 /* generic VNICC request call back */ 1582 static int qeth_l2_vnicc_request_cb(struct qeth_card *card, 1583 struct qeth_reply *reply, 1584 unsigned long data) 1585 { 1586 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1587 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc; 1588 u32 sub_cmd = cmd->data.vnicc.hdr.sub_command; 1589 1590 QETH_CARD_TEXT(card, 2, "vniccrcb"); 1591 if (cmd->hdr.return_code) 1592 return qeth_l2_vnicc_makerc(card, cmd->hdr.return_code); 1593 /* return results to caller */ 1594 card->options.vnicc.sup_chars = rep->vnicc_cmds.supported; 1595 card->options.vnicc.cur_chars = rep->vnicc_cmds.enabled; 1596 1597 if (sub_cmd == IPA_VNICC_QUERY_CMDS) 1598 *(u32 *)reply->param = rep->data.query_cmds.sup_cmds; 1599 else if (sub_cmd == IPA_VNICC_GET_TIMEOUT) 1600 *(u32 *)reply->param = rep->data.getset_timeout.timeout; 1601 1602 return 0; 1603 } 1604 1605 static struct qeth_cmd_buffer *qeth_l2_vnicc_build_cmd(struct qeth_card *card, 1606 u32 vnicc_cmd, 1607 unsigned int data_length) 1608 { 1609 struct qeth_ipacmd_vnicc_hdr *hdr; 1610 struct qeth_cmd_buffer *iob; 1611 1612 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_VNICC, QETH_PROT_NONE, 1613 data_length + 1614 offsetof(struct qeth_ipacmd_vnicc, data)); 1615 if (!iob) 1616 return NULL; 1617 1618 hdr = &__ipa_cmd(iob)->data.vnicc.hdr; 1619 hdr->data_length = sizeof(*hdr) + data_length; 1620 hdr->sub_command = vnicc_cmd; 1621 return iob; 1622 } 1623 1624 /* VNICC query VNIC characteristics request */ 1625 static int qeth_l2_vnicc_query_chars(struct qeth_card *card) 1626 { 1627 struct qeth_cmd_buffer *iob; 1628 1629 QETH_CARD_TEXT(card, 2, "vniccqch"); 1630 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CHARS, 0); 1631 if (!iob) 1632 return -ENOMEM; 1633 1634 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL); 1635 } 1636 1637 /* VNICC query sub commands request */ 1638 static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char, 1639 u32 *sup_cmds) 1640 { 1641 struct qeth_cmd_buffer *iob; 1642 1643 QETH_CARD_TEXT(card, 2, "vniccqcm"); 1644 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CMDS, 1645 VNICC_DATA_SIZEOF(query_cmds)); 1646 if (!iob) 1647 return -ENOMEM; 1648 1649 __ipa_cmd(iob)->data.vnicc.data.query_cmds.vnic_char = vnic_char; 1650 1651 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, sup_cmds); 1652 } 1653 1654 /* VNICC enable/disable characteristic request */ 1655 static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char, 1656 u32 cmd) 1657 { 1658 struct qeth_cmd_buffer *iob; 1659 1660 QETH_CARD_TEXT(card, 2, "vniccedc"); 1661 iob = qeth_l2_vnicc_build_cmd(card, cmd, VNICC_DATA_SIZEOF(set_char)); 1662 if (!iob) 1663 return -ENOMEM; 1664 1665 __ipa_cmd(iob)->data.vnicc.data.set_char.vnic_char = vnic_char; 1666 1667 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL); 1668 } 1669 1670 /* VNICC get/set timeout for characteristic request */ 1671 static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc, 1672 u32 cmd, u32 *timeout) 1673 { 1674 struct qeth_vnicc_getset_timeout *getset_timeout; 1675 struct qeth_cmd_buffer *iob; 1676 1677 QETH_CARD_TEXT(card, 2, "vniccgst"); 1678 iob = qeth_l2_vnicc_build_cmd(card, cmd, 1679 VNICC_DATA_SIZEOF(getset_timeout)); 1680 if (!iob) 1681 return -ENOMEM; 1682 1683 getset_timeout = &__ipa_cmd(iob)->data.vnicc.data.getset_timeout; 1684 getset_timeout->vnic_char = vnicc; 1685 1686 if (cmd == IPA_VNICC_SET_TIMEOUT) 1687 getset_timeout->timeout = *timeout; 1688 1689 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, timeout); 1690 } 1691 1692 /* set current VNICC flag state; called from sysfs store function */ 1693 int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state) 1694 { 1695 int rc = 0; 1696 u32 cmd; 1697 1698 QETH_CARD_TEXT(card, 2, "vniccsch"); 1699 1700 /* check if characteristic and enable/disable are supported */ 1701 if (!(card->options.vnicc.sup_chars & vnicc) || 1702 !(card->options.vnicc.set_char_sup & vnicc)) 1703 return -EOPNOTSUPP; 1704 1705 if (qeth_bridgeport_is_in_use(card)) 1706 return -EBUSY; 1707 1708 /* set enable/disable command and store wanted characteristic */ 1709 if (state) { 1710 cmd = IPA_VNICC_ENABLE; 1711 card->options.vnicc.wanted_chars |= vnicc; 1712 } else { 1713 cmd = IPA_VNICC_DISABLE; 1714 card->options.vnicc.wanted_chars &= ~vnicc; 1715 } 1716 1717 /* do we need to do anything? */ 1718 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars) 1719 return rc; 1720 1721 /* if card is not ready, simply stop here */ 1722 if (!qeth_card_hw_is_reachable(card)) { 1723 if (state) 1724 card->options.vnicc.cur_chars |= vnicc; 1725 else 1726 card->options.vnicc.cur_chars &= ~vnicc; 1727 return rc; 1728 } 1729 1730 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd); 1731 if (rc) 1732 card->options.vnicc.wanted_chars = 1733 card->options.vnicc.cur_chars; 1734 else { 1735 /* successful online VNICC change; handle special cases */ 1736 if (state && vnicc == QETH_VNICC_RX_BCAST) 1737 card->options.vnicc.rx_bcast_enabled = true; 1738 if (!state && vnicc == QETH_VNICC_LEARNING) 1739 qeth_l2_vnicc_recover_timeout(card, vnicc, 1740 &card->options.vnicc.learning_timeout); 1741 } 1742 1743 return rc; 1744 } 1745 1746 /* get current VNICC flag state; called from sysfs show function */ 1747 int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state) 1748 { 1749 int rc = 0; 1750 1751 QETH_CARD_TEXT(card, 2, "vniccgch"); 1752 1753 /* check if characteristic is supported */ 1754 if (!(card->options.vnicc.sup_chars & vnicc)) 1755 return -EOPNOTSUPP; 1756 1757 if (qeth_bridgeport_is_in_use(card)) 1758 return -EBUSY; 1759 1760 /* if card is ready, query current VNICC state */ 1761 if (qeth_card_hw_is_reachable(card)) 1762 rc = qeth_l2_vnicc_query_chars(card); 1763 1764 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false; 1765 return rc; 1766 } 1767 1768 /* set VNICC timeout; called from sysfs store function. Currently, only learning 1769 * supports timeout 1770 */ 1771 int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout) 1772 { 1773 int rc = 0; 1774 1775 QETH_CARD_TEXT(card, 2, "vniccsto"); 1776 1777 /* check if characteristic and set_timeout are supported */ 1778 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) || 1779 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING)) 1780 return -EOPNOTSUPP; 1781 1782 if (qeth_bridgeport_is_in_use(card)) 1783 return -EBUSY; 1784 1785 /* do we need to do anything? */ 1786 if (card->options.vnicc.learning_timeout == timeout) 1787 return rc; 1788 1789 /* if card is not ready, simply store the value internally and return */ 1790 if (!qeth_card_hw_is_reachable(card)) { 1791 card->options.vnicc.learning_timeout = timeout; 1792 return rc; 1793 } 1794 1795 /* send timeout value to card; if successful, store value internally */ 1796 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING, 1797 IPA_VNICC_SET_TIMEOUT, &timeout); 1798 if (!rc) 1799 card->options.vnicc.learning_timeout = timeout; 1800 1801 return rc; 1802 } 1803 1804 /* get current VNICC timeout; called from sysfs show function. Currently, only 1805 * learning supports timeout 1806 */ 1807 int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout) 1808 { 1809 int rc = 0; 1810 1811 QETH_CARD_TEXT(card, 2, "vniccgto"); 1812 1813 /* check if characteristic and get_timeout are supported */ 1814 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) || 1815 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING)) 1816 return -EOPNOTSUPP; 1817 1818 if (qeth_bridgeport_is_in_use(card)) 1819 return -EBUSY; 1820 1821 /* if card is ready, get timeout. Otherwise, just return stored value */ 1822 *timeout = card->options.vnicc.learning_timeout; 1823 if (qeth_card_hw_is_reachable(card)) 1824 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING, 1825 IPA_VNICC_GET_TIMEOUT, 1826 timeout); 1827 1828 return rc; 1829 } 1830 1831 /* check if VNICC is currently enabled */ 1832 bool qeth_l2_vnicc_is_in_use(struct qeth_card *card) 1833 { 1834 if (!card->options.vnicc.sup_chars) 1835 return false; 1836 /* default values are only OK if rx_bcast was not enabled by user 1837 * or the card is offline. 1838 */ 1839 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) { 1840 if (!card->options.vnicc.rx_bcast_enabled || 1841 !qeth_card_hw_is_reachable(card)) 1842 return false; 1843 } 1844 return true; 1845 } 1846 1847 /* recover user timeout setting */ 1848 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc, 1849 u32 *timeout) 1850 { 1851 if (card->options.vnicc.sup_chars & vnicc && 1852 card->options.vnicc.getset_timeout_sup & vnicc && 1853 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT, 1854 timeout)) 1855 return false; 1856 *timeout = QETH_VNICC_DEFAULT_TIMEOUT; 1857 return true; 1858 } 1859 1860 /* recover user characteristic setting */ 1861 static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc, 1862 bool enable) 1863 { 1864 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE; 1865 1866 if (card->options.vnicc.sup_chars & vnicc && 1867 card->options.vnicc.set_char_sup & vnicc && 1868 !qeth_l2_vnicc_set_char(card, vnicc, cmd)) 1869 return false; 1870 card->options.vnicc.wanted_chars &= ~vnicc; 1871 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc; 1872 return true; 1873 } 1874 1875 /* (re-)initialize VNICC */ 1876 static void qeth_l2_vnicc_init(struct qeth_card *card) 1877 { 1878 u32 *timeout = &card->options.vnicc.learning_timeout; 1879 bool enable, error = false; 1880 unsigned int chars_len, i; 1881 unsigned long chars_tmp; 1882 u32 sup_cmds, vnicc; 1883 1884 QETH_CARD_TEXT(card, 2, "vniccini"); 1885 /* reset rx_bcast */ 1886 card->options.vnicc.rx_bcast_enabled = 0; 1887 /* initial query and storage of VNIC characteristics */ 1888 if (qeth_l2_vnicc_query_chars(card)) { 1889 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT || 1890 *timeout != QETH_VNICC_DEFAULT_TIMEOUT) 1891 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n"); 1892 /* fail quietly if user didn't change the default config */ 1893 card->options.vnicc.sup_chars = 0; 1894 card->options.vnicc.cur_chars = 0; 1895 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT; 1896 return; 1897 } 1898 /* get supported commands for each supported characteristic */ 1899 chars_tmp = card->options.vnicc.sup_chars; 1900 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE; 1901 for_each_set_bit(i, &chars_tmp, chars_len) { 1902 vnicc = BIT(i); 1903 if (qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds)) { 1904 sup_cmds = 0; 1905 error = true; 1906 } 1907 if ((sup_cmds & IPA_VNICC_SET_TIMEOUT) && 1908 (sup_cmds & IPA_VNICC_GET_TIMEOUT)) 1909 card->options.vnicc.getset_timeout_sup |= vnicc; 1910 else 1911 card->options.vnicc.getset_timeout_sup &= ~vnicc; 1912 if ((sup_cmds & IPA_VNICC_ENABLE) && 1913 (sup_cmds & IPA_VNICC_DISABLE)) 1914 card->options.vnicc.set_char_sup |= vnicc; 1915 else 1916 card->options.vnicc.set_char_sup &= ~vnicc; 1917 } 1918 /* enforce assumed default values and recover settings, if changed */ 1919 error |= qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING, 1920 timeout); 1921 /* Change chars, if necessary */ 1922 chars_tmp = card->options.vnicc.wanted_chars ^ 1923 card->options.vnicc.cur_chars; 1924 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE; 1925 for_each_set_bit(i, &chars_tmp, chars_len) { 1926 vnicc = BIT(i); 1927 enable = card->options.vnicc.wanted_chars & vnicc; 1928 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable); 1929 } 1930 if (error) 1931 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n"); 1932 } 1933 1934 /* configure default values of VNIC characteristics */ 1935 static void qeth_l2_vnicc_set_defaults(struct qeth_card *card) 1936 { 1937 /* characteristics values */ 1938 card->options.vnicc.sup_chars = QETH_VNICC_ALL; 1939 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT; 1940 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT; 1941 /* supported commands */ 1942 card->options.vnicc.set_char_sup = QETH_VNICC_ALL; 1943 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING; 1944 /* settings wanted by users */ 1945 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT; 1946 } 1947 1948 module_init(qeth_l2_init); 1949 module_exit(qeth_l2_exit); 1950 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); 1951 MODULE_DESCRIPTION("qeth layer 2 discipline"); 1952 MODULE_LICENSE("GPL"); 1953