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/if_bridge.h> 21 #include <linux/list.h> 22 #include <linux/hash.h> 23 #include <linux/hashtable.h> 24 #include <net/switchdev.h> 25 #include <asm/chsc.h> 26 #include <asm/css_chars.h> 27 #include <asm/setup.h> 28 #include "qeth_core.h" 29 #include "qeth_l2.h" 30 31 static int qeth_l2_setdelmac_makerc(struct qeth_card *card, u16 retcode) 32 { 33 int rc; 34 35 if (retcode) 36 QETH_CARD_TEXT_(card, 2, "err%04x", retcode); 37 switch (retcode) { 38 case IPA_RC_SUCCESS: 39 rc = 0; 40 break; 41 case IPA_RC_L2_UNSUPPORTED_CMD: 42 rc = -EOPNOTSUPP; 43 break; 44 case IPA_RC_L2_ADDR_TABLE_FULL: 45 rc = -ENOSPC; 46 break; 47 case IPA_RC_L2_DUP_MAC: 48 case IPA_RC_L2_DUP_LAYER3_MAC: 49 rc = -EADDRINUSE; 50 break; 51 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP: 52 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: 53 rc = -EADDRNOTAVAIL; 54 break; 55 case IPA_RC_L2_MAC_NOT_FOUND: 56 rc = -ENOENT; 57 break; 58 default: 59 rc = -EIO; 60 break; 61 } 62 return rc; 63 } 64 65 static int qeth_l2_send_setdelmac_cb(struct qeth_card *card, 66 struct qeth_reply *reply, 67 unsigned long data) 68 { 69 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 70 71 return qeth_l2_setdelmac_makerc(card, cmd->hdr.return_code); 72 } 73 74 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac, 75 enum qeth_ipa_cmds ipacmd) 76 { 77 struct qeth_ipa_cmd *cmd; 78 struct qeth_cmd_buffer *iob; 79 80 QETH_CARD_TEXT(card, 2, "L2sdmac"); 81 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4, 82 IPA_DATA_SIZEOF(setdelmac)); 83 if (!iob) 84 return -ENOMEM; 85 cmd = __ipa_cmd(iob); 86 cmd->data.setdelmac.mac_length = ETH_ALEN; 87 ether_addr_copy(cmd->data.setdelmac.mac, mac); 88 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelmac_cb, NULL); 89 } 90 91 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac) 92 { 93 int rc; 94 95 QETH_CARD_TEXT(card, 2, "L2Setmac"); 96 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC); 97 if (rc == 0) { 98 dev_info(&card->gdev->dev, 99 "MAC address %pM successfully registered\n", mac); 100 } else { 101 switch (rc) { 102 case -EADDRINUSE: 103 dev_warn(&card->gdev->dev, 104 "MAC address %pM already exists\n", mac); 105 break; 106 case -EADDRNOTAVAIL: 107 dev_warn(&card->gdev->dev, 108 "MAC address %pM is not authorized\n", mac); 109 break; 110 } 111 } 112 return rc; 113 } 114 115 static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac) 116 { 117 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ? 118 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC; 119 int rc; 120 121 QETH_CARD_TEXT(card, 2, "L2Wmac"); 122 rc = qeth_l2_send_setdelmac(card, mac, cmd); 123 if (rc == -EADDRINUSE) 124 QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n", 125 CARD_DEVID(card)); 126 else if (rc) 127 QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n", 128 CARD_DEVID(card), rc); 129 return rc; 130 } 131 132 static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac) 133 { 134 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ? 135 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC; 136 int rc; 137 138 QETH_CARD_TEXT(card, 2, "L2Rmac"); 139 rc = qeth_l2_send_setdelmac(card, mac, cmd); 140 if (rc) 141 QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n", 142 CARD_DEVID(card), rc); 143 return rc; 144 } 145 146 static void qeth_l2_drain_rx_mode_cache(struct qeth_card *card) 147 { 148 struct qeth_mac *mac; 149 struct hlist_node *tmp; 150 int i; 151 152 hash_for_each_safe(card->rx_mode_addrs, i, tmp, mac, hnode) { 153 hash_del(&mac->hnode); 154 kfree(mac); 155 } 156 } 157 158 static void qeth_l2_fill_header(struct qeth_qdio_out_q *queue, 159 struct qeth_hdr *hdr, struct sk_buff *skb, 160 __be16 proto, unsigned int data_len) 161 { 162 int cast_type = qeth_get_ether_cast_type(skb); 163 struct vlan_ethhdr *veth = vlan_eth_hdr(skb); 164 165 hdr->hdr.l2.pkt_length = data_len; 166 167 if (skb_is_gso(skb)) { 168 hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO; 169 } else { 170 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; 171 if (skb->ip_summed == CHECKSUM_PARTIAL) 172 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], proto); 173 } 174 175 /* set byte byte 3 to casting flags */ 176 if (cast_type == RTN_MULTICAST) 177 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST; 178 else if (cast_type == RTN_BROADCAST) 179 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST; 180 else 181 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST; 182 183 /* VSWITCH relies on the VLAN 184 * information to be present in 185 * the QDIO header */ 186 if (veth->h_vlan_proto == htons(ETH_P_8021Q)) { 187 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN; 188 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI); 189 } 190 } 191 192 static int qeth_l2_setdelvlan_makerc(struct qeth_card *card, u16 retcode) 193 { 194 if (retcode) 195 QETH_CARD_TEXT_(card, 2, "err%04x", retcode); 196 197 switch (retcode) { 198 case IPA_RC_SUCCESS: 199 return 0; 200 case IPA_RC_L2_INVALID_VLAN_ID: 201 return -EINVAL; 202 case IPA_RC_L2_DUP_VLAN_ID: 203 return -EEXIST; 204 case IPA_RC_L2_VLAN_ID_NOT_FOUND: 205 return -ENOENT; 206 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED: 207 return -EPERM; 208 default: 209 return -EIO; 210 } 211 } 212 213 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card, 214 struct qeth_reply *reply, 215 unsigned long data) 216 { 217 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 218 219 QETH_CARD_TEXT(card, 2, "L2sdvcb"); 220 if (cmd->hdr.return_code) { 221 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n", 222 cmd->data.setdelvlan.vlan_id, 223 CARD_DEVID(card), cmd->hdr.return_code); 224 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command); 225 } 226 return qeth_l2_setdelvlan_makerc(card, cmd->hdr.return_code); 227 } 228 229 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i, 230 enum qeth_ipa_cmds ipacmd) 231 { 232 struct qeth_ipa_cmd *cmd; 233 struct qeth_cmd_buffer *iob; 234 235 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd); 236 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4, 237 IPA_DATA_SIZEOF(setdelvlan)); 238 if (!iob) 239 return -ENOMEM; 240 cmd = __ipa_cmd(iob); 241 cmd->data.setdelvlan.vlan_id = i; 242 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelvlan_cb, NULL); 243 } 244 245 static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, 246 __be16 proto, u16 vid) 247 { 248 struct qeth_card *card = dev->ml_priv; 249 250 QETH_CARD_TEXT_(card, 4, "aid:%d", vid); 251 if (!vid) 252 return 0; 253 254 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); 255 } 256 257 static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, 258 __be16 proto, u16 vid) 259 { 260 struct qeth_card *card = dev->ml_priv; 261 262 QETH_CARD_TEXT_(card, 4, "kid:%d", vid); 263 if (!vid) 264 return 0; 265 266 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); 267 } 268 269 static void qeth_l2_set_pnso_mode(struct qeth_card *card, 270 enum qeth_pnso_mode mode) 271 { 272 spin_lock_irq(get_ccwdev_lock(CARD_RDEV(card))); 273 WRITE_ONCE(card->info.pnso_mode, mode); 274 spin_unlock_irq(get_ccwdev_lock(CARD_RDEV(card))); 275 276 if (mode == QETH_PNSO_NONE) 277 drain_workqueue(card->event_wq); 278 } 279 280 static void qeth_l2_dev2br_fdb_flush(struct qeth_card *card) 281 { 282 struct switchdev_notifier_fdb_info info; 283 284 QETH_CARD_TEXT(card, 2, "fdbflush"); 285 286 info.addr = NULL; 287 /* flush all VLANs: */ 288 info.vid = 0; 289 info.added_by_user = false; 290 info.offloaded = true; 291 292 call_switchdev_notifiers(SWITCHDEV_FDB_FLUSH_TO_BRIDGE, 293 card->dev, &info.info, NULL); 294 } 295 296 static int qeth_l2_request_initial_mac(struct qeth_card *card) 297 { 298 int rc = 0; 299 300 QETH_CARD_TEXT(card, 2, "l2reqmac"); 301 302 if (MACHINE_IS_VM) { 303 rc = qeth_vm_request_mac(card); 304 if (!rc) 305 goto out; 306 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n", 307 CARD_DEVID(card), rc); 308 QETH_CARD_TEXT_(card, 2, "err%04x", rc); 309 /* fall back to alternative mechanism: */ 310 } 311 312 if (!IS_OSN(card)) { 313 rc = qeth_setadpparms_change_macaddr(card); 314 if (!rc) 315 goto out; 316 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n", 317 CARD_DEVID(card), rc); 318 QETH_CARD_TEXT_(card, 2, "1err%04x", rc); 319 /* fall back once more: */ 320 } 321 322 /* some devices don't support a custom MAC address: */ 323 if (IS_OSM(card) || IS_OSX(card)) 324 return (rc) ? rc : -EADDRNOTAVAIL; 325 eth_hw_addr_random(card->dev); 326 327 out: 328 QETH_CARD_HEX(card, 2, card->dev->dev_addr, card->dev->addr_len); 329 return 0; 330 } 331 332 static void qeth_l2_register_dev_addr(struct qeth_card *card) 333 { 334 if (!is_valid_ether_addr(card->dev->dev_addr)) 335 qeth_l2_request_initial_mac(card); 336 337 if (!IS_OSN(card) && !qeth_l2_send_setmac(card, card->dev->dev_addr)) 338 card->info.dev_addr_is_registered = 1; 339 else 340 card->info.dev_addr_is_registered = 0; 341 } 342 343 static int qeth_l2_validate_addr(struct net_device *dev) 344 { 345 struct qeth_card *card = dev->ml_priv; 346 347 if (card->info.dev_addr_is_registered) 348 return eth_validate_addr(dev); 349 350 QETH_CARD_TEXT(card, 4, "nomacadr"); 351 return -EPERM; 352 } 353 354 static int qeth_l2_set_mac_address(struct net_device *dev, void *p) 355 { 356 struct sockaddr *addr = p; 357 struct qeth_card *card = dev->ml_priv; 358 u8 old_addr[ETH_ALEN]; 359 int rc = 0; 360 361 QETH_CARD_TEXT(card, 3, "setmac"); 362 363 if (IS_OSM(card) || IS_OSX(card)) { 364 QETH_CARD_TEXT(card, 3, "setmcTYP"); 365 return -EOPNOTSUPP; 366 } 367 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN); 368 if (!is_valid_ether_addr(addr->sa_data)) 369 return -EADDRNOTAVAIL; 370 371 /* don't register the same address twice */ 372 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) && 373 card->info.dev_addr_is_registered) 374 return 0; 375 376 /* add the new address, switch over, drop the old */ 377 rc = qeth_l2_send_setmac(card, addr->sa_data); 378 if (rc) 379 return rc; 380 ether_addr_copy(old_addr, dev->dev_addr); 381 ether_addr_copy(dev->dev_addr, addr->sa_data); 382 383 if (card->info.dev_addr_is_registered) 384 qeth_l2_remove_mac(card, old_addr); 385 card->info.dev_addr_is_registered = 1; 386 return 0; 387 } 388 389 static void qeth_l2_promisc_to_bridge(struct qeth_card *card, bool enable) 390 { 391 int role; 392 int rc; 393 394 QETH_CARD_TEXT(card, 3, "pmisc2br"); 395 396 if (enable) { 397 if (card->options.sbp.reflect_promisc_primary) 398 role = QETH_SBP_ROLE_PRIMARY; 399 else 400 role = QETH_SBP_ROLE_SECONDARY; 401 } else 402 role = QETH_SBP_ROLE_NONE; 403 404 rc = qeth_bridgeport_setrole(card, role); 405 QETH_CARD_TEXT_(card, 2, "bpm%c%04x", enable ? '+' : '-', rc); 406 if (!rc) { 407 card->options.sbp.role = role; 408 card->info.promisc_mode = enable; 409 } 410 } 411 412 static void qeth_l2_set_promisc_mode(struct qeth_card *card) 413 { 414 bool enable = card->dev->flags & IFF_PROMISC; 415 416 if (card->info.promisc_mode == enable) 417 return; 418 419 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) { 420 qeth_setadp_promisc_mode(card, enable); 421 } else { 422 mutex_lock(&card->sbp_lock); 423 if (card->options.sbp.reflect_promisc) 424 qeth_l2_promisc_to_bridge(card, enable); 425 mutex_unlock(&card->sbp_lock); 426 } 427 } 428 429 /* New MAC address is added to the hash table and marked to be written on card 430 * only if there is not in the hash table storage already 431 * 432 */ 433 static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha) 434 { 435 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2])); 436 struct qeth_mac *mac; 437 438 hash_for_each_possible(card->rx_mode_addrs, mac, hnode, mac_hash) { 439 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) { 440 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 441 return; 442 } 443 } 444 445 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC); 446 if (!mac) 447 return; 448 449 ether_addr_copy(mac->mac_addr, ha->addr); 450 mac->disp_flag = QETH_DISP_ADDR_ADD; 451 452 hash_add(card->rx_mode_addrs, &mac->hnode, mac_hash); 453 } 454 455 static void qeth_l2_rx_mode_work(struct work_struct *work) 456 { 457 struct qeth_card *card = container_of(work, struct qeth_card, 458 rx_mode_work); 459 struct net_device *dev = card->dev; 460 struct netdev_hw_addr *ha; 461 struct qeth_mac *mac; 462 struct hlist_node *tmp; 463 int i; 464 int rc; 465 466 QETH_CARD_TEXT(card, 3, "setmulti"); 467 468 netif_addr_lock_bh(dev); 469 netdev_for_each_mc_addr(ha, dev) 470 qeth_l2_add_mac(card, ha); 471 netdev_for_each_uc_addr(ha, dev) 472 qeth_l2_add_mac(card, ha); 473 netif_addr_unlock_bh(dev); 474 475 hash_for_each_safe(card->rx_mode_addrs, i, tmp, mac, hnode) { 476 switch (mac->disp_flag) { 477 case QETH_DISP_ADDR_DELETE: 478 qeth_l2_remove_mac(card, mac->mac_addr); 479 hash_del(&mac->hnode); 480 kfree(mac); 481 break; 482 case QETH_DISP_ADDR_ADD: 483 rc = qeth_l2_write_mac(card, mac->mac_addr); 484 if (rc) { 485 hash_del(&mac->hnode); 486 kfree(mac); 487 break; 488 } 489 fallthrough; 490 default: 491 /* for next call to set_rx_mode(): */ 492 mac->disp_flag = QETH_DISP_ADDR_DELETE; 493 } 494 } 495 496 qeth_l2_set_promisc_mode(card); 497 } 498 499 static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb, 500 struct qeth_qdio_out_q *queue) 501 { 502 gfp_t gfp = GFP_ATOMIC | (skb_pfmemalloc(skb) ? __GFP_MEMALLOC : 0); 503 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data; 504 addr_t end = (addr_t)(skb->data + sizeof(*hdr)); 505 addr_t start = (addr_t)skb->data; 506 unsigned int elements = 0; 507 unsigned int hd_len = 0; 508 int rc; 509 510 if (skb->protocol == htons(ETH_P_IPV6)) 511 return -EPROTONOSUPPORT; 512 513 if (qeth_get_elements_for_range(start, end) > 1) { 514 /* Misaligned HW header, move it to its own buffer element. */ 515 hdr = kmem_cache_alloc(qeth_core_header_cache, gfp); 516 if (!hdr) 517 return -ENOMEM; 518 hd_len = sizeof(*hdr); 519 skb_copy_from_linear_data(skb, (char *)hdr, hd_len); 520 elements++; 521 } 522 523 elements += qeth_count_elements(skb, hd_len); 524 if (elements > queue->max_elements) { 525 rc = -E2BIG; 526 goto out; 527 } 528 529 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len, 530 elements); 531 out: 532 if (rc && hd_len) 533 kmem_cache_free(qeth_core_header_cache, hdr); 534 return rc; 535 } 536 537 static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb, 538 struct net_device *dev) 539 { 540 struct qeth_card *card = dev->ml_priv; 541 u16 txq = skb_get_queue_mapping(skb); 542 struct qeth_qdio_out_q *queue; 543 int rc; 544 545 if (!skb_is_gso(skb)) 546 qdisc_skb_cb(skb)->pkt_len = skb->len; 547 if (IS_IQD(card)) 548 txq = qeth_iqd_translate_txq(dev, txq); 549 queue = card->qdio.out_qs[txq]; 550 551 if (IS_OSN(card)) 552 rc = qeth_l2_xmit_osn(card, skb, queue); 553 else 554 rc = qeth_xmit(card, skb, queue, vlan_get_protocol(skb), 555 qeth_l2_fill_header); 556 557 if (!rc) 558 return NETDEV_TX_OK; 559 560 QETH_TXQ_STAT_INC(queue, tx_dropped); 561 kfree_skb(skb); 562 return NETDEV_TX_OK; 563 } 564 565 static u16 qeth_l2_select_queue(struct net_device *dev, struct sk_buff *skb, 566 struct net_device *sb_dev) 567 { 568 struct qeth_card *card = dev->ml_priv; 569 570 if (IS_IQD(card)) 571 return qeth_iqd_select_queue(dev, skb, 572 qeth_get_ether_cast_type(skb), 573 sb_dev); 574 if (qeth_uses_tx_prio_queueing(card)) 575 return qeth_get_priority_queue(card, skb); 576 577 return netdev_pick_tx(dev, skb, sb_dev); 578 } 579 580 static void qeth_l2_set_rx_mode(struct net_device *dev) 581 { 582 struct qeth_card *card = dev->ml_priv; 583 584 schedule_work(&card->rx_mode_work); 585 } 586 587 /** 588 * qeth_l2_pnso() - perform network subchannel operation 589 * @card: qeth_card structure pointer 590 * @oc: Operation Code 591 * @cnc: Boolean Change-Notification Control 592 * @cb: Callback function will be executed for each element 593 * of the address list 594 * @priv: Pointer to pass to the callback function. 595 * 596 * Collects network information in a network address list and calls the 597 * callback function for every entry in the list. If "change-notification- 598 * control" is set, further changes in the address list will be reported 599 * via the IPA command. 600 */ 601 static int qeth_l2_pnso(struct qeth_card *card, u8 oc, int cnc, 602 void (*cb)(void *priv, struct chsc_pnso_naid_l2 *entry), 603 void *priv) 604 { 605 struct ccw_device *ddev = CARD_DDEV(card); 606 struct chsc_pnso_area *rr; 607 u32 prev_instance = 0; 608 int isfirstblock = 1; 609 int i, size, elems; 610 int rc; 611 612 rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL); 613 if (rr == NULL) 614 return -ENOMEM; 615 do { 616 QETH_CARD_TEXT(card, 2, "PNSO"); 617 /* on the first iteration, naihdr.resume_token will be zero */ 618 rc = ccw_device_pnso(ddev, rr, oc, rr->naihdr.resume_token, 619 cnc); 620 if (rc) 621 continue; 622 if (cb == NULL) 623 continue; 624 625 size = rr->naihdr.naids; 626 if (size != sizeof(struct chsc_pnso_naid_l2)) { 627 WARN_ON_ONCE(1); 628 continue; 629 } 630 631 elems = (rr->response.length - sizeof(struct chsc_header) - 632 sizeof(struct chsc_pnso_naihdr)) / size; 633 634 if (!isfirstblock && (rr->naihdr.instance != prev_instance)) { 635 /* Inform the caller that they need to scrap */ 636 /* the data that was already reported via cb */ 637 rc = -EAGAIN; 638 break; 639 } 640 isfirstblock = 0; 641 prev_instance = rr->naihdr.instance; 642 for (i = 0; i < elems; i++) 643 (*cb)(priv, &rr->entries[i]); 644 } while ((rc == -EBUSY) || (!rc && /* list stored */ 645 /* resume token is non-zero => list incomplete */ 646 (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2))); 647 648 if (rc) 649 QETH_CARD_TEXT_(card, 2, "PNrp%04x", rr->response.code); 650 651 free_page((unsigned long)rr); 652 return rc; 653 } 654 655 static bool qeth_is_my_net_if_token(struct qeth_card *card, 656 struct net_if_token *token) 657 { 658 return ((card->info.ddev_devno == token->devnum) && 659 (card->info.cssid == token->cssid) && 660 (card->info.iid == token->iid) && 661 (card->info.ssid == token->ssid) && 662 (card->info.chpid == token->chpid) && 663 (card->info.chid == token->chid)); 664 } 665 666 /** 667 * qeth_l2_dev2br_fdb_notify() - update fdb of master bridge 668 * @card: qeth_card structure pointer 669 * @code: event bitmask: high order bit 0x80 set to 670 * 1 - removal of an object 671 * 0 - addition of an object 672 * Object type(s): 673 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC 674 * @token: "network token" structure identifying 'physical' location 675 * of the target 676 * @addr_lnid: structure with MAC address and VLAN ID of the target 677 */ 678 static void qeth_l2_dev2br_fdb_notify(struct qeth_card *card, u8 code, 679 struct net_if_token *token, 680 struct mac_addr_lnid *addr_lnid) 681 { 682 struct switchdev_notifier_fdb_info info; 683 u8 ntfy_mac[ETH_ALEN]; 684 685 ether_addr_copy(ntfy_mac, addr_lnid->mac); 686 /* Ignore VLAN only changes */ 687 if (!(code & IPA_ADDR_CHANGE_CODE_MACADDR)) 688 return; 689 /* Ignore mcast entries */ 690 if (is_multicast_ether_addr(ntfy_mac)) 691 return; 692 /* Ignore my own addresses */ 693 if (qeth_is_my_net_if_token(card, token)) 694 return; 695 696 info.addr = ntfy_mac; 697 /* don't report VLAN IDs */ 698 info.vid = 0; 699 info.added_by_user = false; 700 info.offloaded = true; 701 702 if (code & IPA_ADDR_CHANGE_CODE_REMOVAL) { 703 call_switchdev_notifiers(SWITCHDEV_FDB_DEL_TO_BRIDGE, 704 card->dev, &info.info, NULL); 705 QETH_CARD_TEXT(card, 4, "andelmac"); 706 QETH_CARD_TEXT_(card, 4, 707 "mc%012lx", ether_addr_to_u64(ntfy_mac)); 708 } else { 709 call_switchdev_notifiers(SWITCHDEV_FDB_ADD_TO_BRIDGE, 710 card->dev, &info.info, NULL); 711 QETH_CARD_TEXT(card, 4, "anaddmac"); 712 QETH_CARD_TEXT_(card, 4, 713 "mc%012lx", ether_addr_to_u64(ntfy_mac)); 714 } 715 } 716 717 static void qeth_l2_dev2br_an_set_cb(void *priv, 718 struct chsc_pnso_naid_l2 *entry) 719 { 720 u8 code = IPA_ADDR_CHANGE_CODE_MACADDR; 721 struct qeth_card *card = priv; 722 723 if (entry->addr_lnid.lnid < VLAN_N_VID) 724 code |= IPA_ADDR_CHANGE_CODE_VLANID; 725 qeth_l2_dev2br_fdb_notify(card, code, 726 (struct net_if_token *)&entry->nit, 727 (struct mac_addr_lnid *)&entry->addr_lnid); 728 } 729 730 /** 731 * qeth_l2_dev2br_an_set() - 732 * Enable or disable 'dev to bridge network address notification' 733 * @card: qeth_card structure pointer 734 * @enable: Enable or disable 'dev to bridge network address notification' 735 * 736 * Returns negative errno-compatible error indication or 0 on success. 737 * 738 * On enable, emits a series of address notifications for all 739 * currently registered hosts. 740 */ 741 static int qeth_l2_dev2br_an_set(struct qeth_card *card, bool enable) 742 { 743 int rc; 744 745 if (enable) { 746 QETH_CARD_TEXT(card, 2, "anseton"); 747 rc = qeth_l2_pnso(card, PNSO_OC_NET_ADDR_INFO, 1, 748 qeth_l2_dev2br_an_set_cb, card); 749 if (rc == -EAGAIN) 750 /* address notification enabled, but inconsistent 751 * addresses reported -> disable address notification 752 */ 753 qeth_l2_pnso(card, PNSO_OC_NET_ADDR_INFO, 0, 754 NULL, NULL); 755 } else { 756 QETH_CARD_TEXT(card, 2, "ansetoff"); 757 rc = qeth_l2_pnso(card, PNSO_OC_NET_ADDR_INFO, 0, NULL, NULL); 758 } 759 760 return rc; 761 } 762 763 static int qeth_l2_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 764 struct net_device *dev, u32 filter_mask, 765 int nlflags) 766 { 767 struct qeth_priv *priv = netdev_priv(dev); 768 struct qeth_card *card = dev->ml_priv; 769 u16 mode = BRIDGE_MODE_UNDEF; 770 771 /* Do not even show qeth devs that cannot do bridge_setlink */ 772 if (!priv->brport_hw_features || !netif_device_present(dev) || 773 qeth_bridgeport_is_in_use(card)) 774 return -EOPNOTSUPP; 775 776 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, 777 mode, priv->brport_features, 778 priv->brport_hw_features, 779 nlflags, filter_mask, NULL); 780 } 781 782 static const struct nla_policy qeth_brport_policy[IFLA_BRPORT_MAX + 1] = { 783 [IFLA_BRPORT_LEARNING_SYNC] = { .type = NLA_U8 }, 784 }; 785 786 /** 787 * qeth_l2_bridge_setlink() - set bridgeport attributes 788 * @dev: netdevice 789 * @nlh: netlink message header 790 * @flags: bridge flags (here: BRIDGE_FLAGS_SELF) 791 * @extack: extended ACK report struct 792 * 793 * Called under rtnl_lock 794 */ 795 static int qeth_l2_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, 796 u16 flags, struct netlink_ext_ack *extack) 797 { 798 struct qeth_priv *priv = netdev_priv(dev); 799 struct nlattr *bp_tb[IFLA_BRPORT_MAX + 1]; 800 struct qeth_card *card = dev->ml_priv; 801 struct nlattr *attr, *nested_attr; 802 bool enable, has_protinfo = false; 803 int rem1, rem2; 804 int rc; 805 806 if (!netif_device_present(dev)) 807 return -ENODEV; 808 809 nlmsg_for_each_attr(attr, nlh, sizeof(struct ifinfomsg), rem1) { 810 if (nla_type(attr) == IFLA_PROTINFO) { 811 rc = nla_parse_nested(bp_tb, IFLA_BRPORT_MAX, attr, 812 qeth_brport_policy, extack); 813 if (rc) 814 return rc; 815 has_protinfo = true; 816 } else if (nla_type(attr) == IFLA_AF_SPEC) { 817 nla_for_each_nested(nested_attr, attr, rem2) { 818 if (nla_type(nested_attr) == IFLA_BRIDGE_FLAGS) 819 continue; 820 NL_SET_ERR_MSG_ATTR(extack, nested_attr, 821 "Unsupported attribute"); 822 return -EINVAL; 823 } 824 } else { 825 NL_SET_ERR_MSG_ATTR(extack, attr, "Unsupported attribute"); 826 return -EINVAL; 827 } 828 } 829 if (!has_protinfo) 830 return 0; 831 if (!bp_tb[IFLA_BRPORT_LEARNING_SYNC]) 832 return -EINVAL; 833 if (!(priv->brport_hw_features & BR_LEARNING_SYNC)) { 834 NL_SET_ERR_MSG_ATTR(extack, bp_tb[IFLA_BRPORT_LEARNING_SYNC], 835 "Operation not supported by HW"); 836 return -EOPNOTSUPP; 837 } 838 if (!IS_ENABLED(CONFIG_NET_SWITCHDEV)) { 839 NL_SET_ERR_MSG_ATTR(extack, bp_tb[IFLA_BRPORT_LEARNING_SYNC], 840 "Requires NET_SWITCHDEV"); 841 return -EOPNOTSUPP; 842 } 843 enable = !!nla_get_u8(bp_tb[IFLA_BRPORT_LEARNING_SYNC]); 844 845 if (enable == !!(priv->brport_features & BR_LEARNING_SYNC)) 846 return 0; 847 848 mutex_lock(&card->sbp_lock); 849 /* do not change anything if BridgePort is enabled */ 850 if (qeth_bridgeport_is_in_use(card)) { 851 NL_SET_ERR_MSG(extack, "n/a (BridgePort)"); 852 rc = -EBUSY; 853 } else if (enable) { 854 qeth_l2_set_pnso_mode(card, QETH_PNSO_ADDR_INFO); 855 rc = qeth_l2_dev2br_an_set(card, true); 856 if (rc) 857 qeth_l2_set_pnso_mode(card, QETH_PNSO_NONE); 858 else 859 priv->brport_features |= BR_LEARNING_SYNC; 860 } else { 861 rc = qeth_l2_dev2br_an_set(card, false); 862 if (!rc) { 863 qeth_l2_set_pnso_mode(card, QETH_PNSO_NONE); 864 priv->brport_features ^= BR_LEARNING_SYNC; 865 qeth_l2_dev2br_fdb_flush(card); 866 } 867 } 868 mutex_unlock(&card->sbp_lock); 869 870 return rc; 871 } 872 873 static const struct net_device_ops qeth_l2_netdev_ops = { 874 .ndo_open = qeth_open, 875 .ndo_stop = qeth_stop, 876 .ndo_get_stats64 = qeth_get_stats64, 877 .ndo_start_xmit = qeth_l2_hard_start_xmit, 878 .ndo_features_check = qeth_features_check, 879 .ndo_select_queue = qeth_l2_select_queue, 880 .ndo_validate_addr = qeth_l2_validate_addr, 881 .ndo_set_rx_mode = qeth_l2_set_rx_mode, 882 .ndo_do_ioctl = qeth_do_ioctl, 883 .ndo_set_mac_address = qeth_l2_set_mac_address, 884 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid, 885 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid, 886 .ndo_tx_timeout = qeth_tx_timeout, 887 .ndo_fix_features = qeth_fix_features, 888 .ndo_set_features = qeth_set_features, 889 .ndo_bridge_getlink = qeth_l2_bridge_getlink, 890 .ndo_bridge_setlink = qeth_l2_bridge_setlink, 891 }; 892 893 static const struct net_device_ops qeth_osn_netdev_ops = { 894 .ndo_open = qeth_open, 895 .ndo_stop = qeth_stop, 896 .ndo_get_stats64 = qeth_get_stats64, 897 .ndo_start_xmit = qeth_l2_hard_start_xmit, 898 .ndo_validate_addr = eth_validate_addr, 899 .ndo_tx_timeout = qeth_tx_timeout, 900 }; 901 902 static int qeth_l2_setup_netdev(struct qeth_card *card) 903 { 904 if (IS_OSN(card)) { 905 card->dev->netdev_ops = &qeth_osn_netdev_ops; 906 card->dev->flags |= IFF_NOARP; 907 goto add_napi; 908 } 909 910 card->dev->needed_headroom = sizeof(struct qeth_hdr); 911 card->dev->netdev_ops = &qeth_l2_netdev_ops; 912 card->dev->priv_flags |= IFF_UNICAST_FLT; 913 914 if (IS_OSM(card)) { 915 card->dev->features |= NETIF_F_VLAN_CHALLENGED; 916 } else { 917 if (!IS_VM_NIC(card)) 918 card->dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER; 919 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; 920 } 921 922 if (IS_OSD(card) && !IS_VM_NIC(card)) { 923 card->dev->features |= NETIF_F_SG; 924 /* OSA 3S and earlier has no RX/TX support */ 925 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) { 926 card->dev->hw_features |= NETIF_F_IP_CSUM; 927 card->dev->vlan_features |= NETIF_F_IP_CSUM; 928 } 929 } 930 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) { 931 card->dev->hw_features |= NETIF_F_IPV6_CSUM; 932 card->dev->vlan_features |= NETIF_F_IPV6_CSUM; 933 } 934 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) || 935 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) { 936 card->dev->hw_features |= NETIF_F_RXCSUM; 937 card->dev->vlan_features |= NETIF_F_RXCSUM; 938 } 939 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) { 940 card->dev->hw_features |= NETIF_F_TSO; 941 card->dev->vlan_features |= NETIF_F_TSO; 942 } 943 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) { 944 card->dev->hw_features |= NETIF_F_TSO6; 945 card->dev->vlan_features |= NETIF_F_TSO6; 946 } 947 948 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) { 949 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso); 950 netif_keep_dst(card->dev); 951 netif_set_gso_max_size(card->dev, 952 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)); 953 } 954 955 add_napi: 956 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); 957 return register_netdev(card->dev); 958 } 959 960 static void qeth_l2_trace_features(struct qeth_card *card) 961 { 962 /* Set BridgePort features */ 963 QETH_CARD_TEXT(card, 2, "featuSBP"); 964 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs, 965 sizeof(card->options.sbp.supported_funcs)); 966 /* VNIC Characteristics features */ 967 QETH_CARD_TEXT(card, 2, "feaVNICC"); 968 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars, 969 sizeof(card->options.vnicc.sup_chars)); 970 } 971 972 static void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card) 973 { 974 if (!card->options.sbp.reflect_promisc && 975 card->options.sbp.role != QETH_SBP_ROLE_NONE) { 976 /* Conditional to avoid spurious error messages */ 977 qeth_bridgeport_setrole(card, card->options.sbp.role); 978 /* Let the callback function refresh the stored role value. */ 979 qeth_bridgeport_query_ports(card, &card->options.sbp.role, 980 NULL); 981 } 982 if (card->options.sbp.hostnotification) { 983 if (qeth_bridgeport_an_set(card, 1)) 984 card->options.sbp.hostnotification = 0; 985 } 986 } 987 988 /** 989 * qeth_l2_detect_dev2br_support() - 990 * Detect whether this card supports 'dev to bridge fdb network address 991 * change notification' and thus can support the learning_sync bridgeport 992 * attribute 993 * @card: qeth_card structure pointer 994 */ 995 static void qeth_l2_detect_dev2br_support(struct qeth_card *card) 996 { 997 struct qeth_priv *priv = netdev_priv(card->dev); 998 bool dev2br_supported; 999 1000 QETH_CARD_TEXT(card, 2, "d2brsup"); 1001 if (!IS_IQD(card)) 1002 return; 1003 1004 /* dev2br requires valid cssid,iid,chid */ 1005 dev2br_supported = card->info.ids_valid && 1006 css_general_characteristics.enarf; 1007 QETH_CARD_TEXT_(card, 2, "D2Bsup%02x", dev2br_supported); 1008 1009 if (dev2br_supported) 1010 priv->brport_hw_features |= BR_LEARNING_SYNC; 1011 else 1012 priv->brport_hw_features &= ~BR_LEARNING_SYNC; 1013 } 1014 1015 static void qeth_l2_enable_brport_features(struct qeth_card *card) 1016 { 1017 struct qeth_priv *priv = netdev_priv(card->dev); 1018 int rc; 1019 1020 if (priv->brport_features & BR_LEARNING_SYNC) { 1021 if (priv->brport_hw_features & BR_LEARNING_SYNC) { 1022 qeth_l2_set_pnso_mode(card, QETH_PNSO_ADDR_INFO); 1023 rc = qeth_l2_dev2br_an_set(card, true); 1024 if (rc == -EAGAIN) { 1025 /* Recoverable error, retry once */ 1026 qeth_l2_set_pnso_mode(card, QETH_PNSO_NONE); 1027 qeth_l2_dev2br_fdb_flush(card); 1028 qeth_l2_set_pnso_mode(card, QETH_PNSO_ADDR_INFO); 1029 rc = qeth_l2_dev2br_an_set(card, true); 1030 } 1031 if (rc) { 1032 netdev_err(card->dev, 1033 "failed to enable bridge learning_sync: %d\n", 1034 rc); 1035 qeth_l2_set_pnso_mode(card, QETH_PNSO_NONE); 1036 qeth_l2_dev2br_fdb_flush(card); 1037 priv->brport_features ^= BR_LEARNING_SYNC; 1038 } 1039 } else { 1040 dev_warn(&card->gdev->dev, 1041 "bridge learning_sync not supported\n"); 1042 priv->brport_features ^= BR_LEARNING_SYNC; 1043 } 1044 } 1045 } 1046 1047 #ifdef CONFIG_QETH_OSN 1048 static void qeth_osn_assist_cb(struct qeth_card *card, 1049 struct qeth_cmd_buffer *iob, 1050 unsigned int data_length) 1051 { 1052 qeth_notify_cmd(iob, 0); 1053 qeth_put_cmd(iob); 1054 } 1055 1056 int qeth_osn_assist(struct net_device *dev, void *data, int data_len) 1057 { 1058 struct qeth_cmd_buffer *iob; 1059 struct qeth_card *card; 1060 1061 if (data_len < 0) 1062 return -EINVAL; 1063 if (!dev) 1064 return -ENODEV; 1065 card = dev->ml_priv; 1066 if (!card) 1067 return -ENODEV; 1068 QETH_CARD_TEXT(card, 2, "osnsdmc"); 1069 if (!qeth_card_hw_is_reachable(card)) 1070 return -ENODEV; 1071 1072 iob = qeth_alloc_cmd(&card->write, IPA_PDU_HEADER_SIZE + data_len, 1, 1073 QETH_IPA_TIMEOUT); 1074 if (!iob) 1075 return -ENOMEM; 1076 1077 qeth_prepare_ipa_cmd(card, iob, (u16) data_len, NULL); 1078 1079 memcpy(__ipa_cmd(iob), data, data_len); 1080 iob->callback = qeth_osn_assist_cb; 1081 return qeth_send_ipa_cmd(card, iob, NULL, NULL); 1082 } 1083 EXPORT_SYMBOL(qeth_osn_assist); 1084 1085 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev, 1086 int (*assist_cb)(struct net_device *, void *), 1087 int (*data_cb)(struct sk_buff *)) 1088 { 1089 struct qeth_card *card; 1090 char bus_id[16]; 1091 u16 devno; 1092 1093 memcpy(&devno, read_dev_no, 2); 1094 sprintf(bus_id, "0.0.%04x", devno); 1095 card = qeth_get_card_by_busid(bus_id); 1096 if (!card || !IS_OSN(card)) 1097 return -ENODEV; 1098 *dev = card->dev; 1099 1100 QETH_CARD_TEXT(card, 2, "osnreg"); 1101 if ((assist_cb == NULL) || (data_cb == NULL)) 1102 return -EINVAL; 1103 card->osn_info.assist_cb = assist_cb; 1104 card->osn_info.data_cb = data_cb; 1105 return 0; 1106 } 1107 EXPORT_SYMBOL(qeth_osn_register); 1108 1109 void qeth_osn_deregister(struct net_device *dev) 1110 { 1111 struct qeth_card *card; 1112 1113 if (!dev) 1114 return; 1115 card = dev->ml_priv; 1116 if (!card) 1117 return; 1118 QETH_CARD_TEXT(card, 2, "osndereg"); 1119 card->osn_info.assist_cb = NULL; 1120 card->osn_info.data_cb = NULL; 1121 } 1122 EXPORT_SYMBOL(qeth_osn_deregister); 1123 #endif 1124 1125 /* SETBRIDGEPORT support, async notifications */ 1126 1127 enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset}; 1128 1129 /** 1130 * qeth_bridge_emit_host_event() - bridgeport address change notification 1131 * @card: qeth_card structure pointer, for udev events. 1132 * @evtype: "normal" register/unregister, or abort, or reset. For abort 1133 * and reset token and addr_lnid are unused and may be NULL. 1134 * @code: event bitmask: high order bit 0x80 value 1 means removal of an 1135 * object, 0 - addition of an object. 1136 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC. 1137 * @token: "network token" structure identifying physical address of the port. 1138 * @addr_lnid: pointer to structure with MAC address and VLAN ID. 1139 * 1140 * This function is called when registrations and deregistrations are 1141 * reported by the hardware, and also when notifications are enabled - 1142 * for all currently registered addresses. 1143 */ 1144 static void qeth_bridge_emit_host_event(struct qeth_card *card, 1145 enum qeth_an_event_type evtype, 1146 u8 code, 1147 struct net_if_token *token, 1148 struct mac_addr_lnid *addr_lnid) 1149 { 1150 char str[7][32]; 1151 char *env[8]; 1152 int i = 0; 1153 1154 switch (evtype) { 1155 case anev_reg_unreg: 1156 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s", 1157 (code & IPA_ADDR_CHANGE_CODE_REMOVAL) 1158 ? "deregister" : "register"); 1159 env[i] = str[i]; i++; 1160 if (code & IPA_ADDR_CHANGE_CODE_VLANID) { 1161 snprintf(str[i], sizeof(str[i]), "VLAN=%d", 1162 addr_lnid->lnid); 1163 env[i] = str[i]; i++; 1164 } 1165 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) { 1166 snprintf(str[i], sizeof(str[i]), "MAC=%pM", 1167 addr_lnid->mac); 1168 env[i] = str[i]; i++; 1169 } 1170 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x", 1171 token->cssid, token->ssid, token->devnum); 1172 env[i] = str[i]; i++; 1173 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid); 1174 env[i] = str[i]; i++; 1175 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x", 1176 token->chpid); 1177 env[i] = str[i]; i++; 1178 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid); 1179 env[i] = str[i]; i++; 1180 break; 1181 case anev_abort: 1182 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort"); 1183 env[i] = str[i]; i++; 1184 break; 1185 case anev_reset: 1186 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset"); 1187 env[i] = str[i]; i++; 1188 break; 1189 } 1190 env[i] = NULL; 1191 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env); 1192 } 1193 1194 struct qeth_bridge_state_data { 1195 struct work_struct worker; 1196 struct qeth_card *card; 1197 u8 role; 1198 u8 state; 1199 }; 1200 1201 static void qeth_bridge_state_change_worker(struct work_struct *work) 1202 { 1203 struct qeth_bridge_state_data *data = 1204 container_of(work, struct qeth_bridge_state_data, worker); 1205 char env_locrem[32]; 1206 char env_role[32]; 1207 char env_state[32]; 1208 char *env[] = { 1209 env_locrem, 1210 env_role, 1211 env_state, 1212 NULL 1213 }; 1214 1215 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange"); 1216 snprintf(env_role, sizeof(env_role), "ROLE=%s", 1217 (data->role == QETH_SBP_ROLE_NONE) ? "none" : 1218 (data->role == QETH_SBP_ROLE_PRIMARY) ? "primary" : 1219 (data->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" : 1220 "<INVALID>"); 1221 snprintf(env_state, sizeof(env_state), "STATE=%s", 1222 (data->state == QETH_SBP_STATE_INACTIVE) ? "inactive" : 1223 (data->state == QETH_SBP_STATE_STANDBY) ? "standby" : 1224 (data->state == QETH_SBP_STATE_ACTIVE) ? "active" : 1225 "<INVALID>"); 1226 kobject_uevent_env(&data->card->gdev->dev.kobj, 1227 KOBJ_CHANGE, env); 1228 kfree(data); 1229 } 1230 1231 static void qeth_bridge_state_change(struct qeth_card *card, 1232 struct qeth_ipa_cmd *cmd) 1233 { 1234 struct qeth_sbp_port_data *qports = &cmd->data.sbp.data.port_data; 1235 struct qeth_bridge_state_data *data; 1236 1237 QETH_CARD_TEXT(card, 2, "brstchng"); 1238 if (qports->num_entries == 0) { 1239 QETH_CARD_TEXT(card, 2, "BPempty"); 1240 return; 1241 } 1242 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { 1243 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length); 1244 return; 1245 } 1246 1247 data = kzalloc(sizeof(*data), GFP_ATOMIC); 1248 if (!data) { 1249 QETH_CARD_TEXT(card, 2, "BPSalloc"); 1250 return; 1251 } 1252 INIT_WORK(&data->worker, qeth_bridge_state_change_worker); 1253 data->card = card; 1254 /* Information for the local port: */ 1255 data->role = qports->entry[0].role; 1256 data->state = qports->entry[0].state; 1257 1258 queue_work(card->event_wq, &data->worker); 1259 } 1260 1261 struct qeth_addr_change_data { 1262 struct delayed_work dwork; 1263 struct qeth_card *card; 1264 struct qeth_ipacmd_addr_change ac_event; 1265 }; 1266 1267 static void qeth_l2_dev2br_worker(struct work_struct *work) 1268 { 1269 struct delayed_work *dwork = to_delayed_work(work); 1270 struct qeth_addr_change_data *data; 1271 struct qeth_card *card; 1272 struct qeth_priv *priv; 1273 unsigned int i; 1274 int rc; 1275 1276 data = container_of(dwork, struct qeth_addr_change_data, dwork); 1277 card = data->card; 1278 priv = netdev_priv(card->dev); 1279 1280 QETH_CARD_TEXT(card, 4, "dev2brew"); 1281 1282 if (READ_ONCE(card->info.pnso_mode) == QETH_PNSO_NONE) 1283 goto free; 1284 1285 if (data->ac_event.lost_event_mask) { 1286 /* Potential re-config in progress, try again later: */ 1287 if (!rtnl_trylock()) { 1288 queue_delayed_work(card->event_wq, dwork, 1289 msecs_to_jiffies(100)); 1290 return; 1291 } 1292 1293 if (!netif_device_present(card->dev)) { 1294 rtnl_unlock(); 1295 goto free; 1296 } 1297 1298 QETH_DBF_MESSAGE(3, 1299 "Address change notification overflow on device %x\n", 1300 CARD_DEVID(card)); 1301 /* Card fdb and bridge fdb are out of sync, card has stopped 1302 * notifications (no need to drain_workqueue). Purge all 1303 * 'extern_learn' entries from the parent bridge and restart 1304 * the notifications. 1305 */ 1306 qeth_l2_dev2br_fdb_flush(card); 1307 rc = qeth_l2_dev2br_an_set(card, true); 1308 if (rc) { 1309 /* TODO: if we want to retry after -EAGAIN, be 1310 * aware there could be stale entries in the 1311 * workqueue now, that need to be drained. 1312 * For now we give up: 1313 */ 1314 netdev_err(card->dev, 1315 "bridge learning_sync failed to recover: %d\n", 1316 rc); 1317 WRITE_ONCE(card->info.pnso_mode, 1318 QETH_PNSO_NONE); 1319 /* To remove fdb entries reported by an_set: */ 1320 qeth_l2_dev2br_fdb_flush(card); 1321 priv->brport_features ^= BR_LEARNING_SYNC; 1322 } else { 1323 QETH_DBF_MESSAGE(3, 1324 "Address Notification resynced on device %x\n", 1325 CARD_DEVID(card)); 1326 } 1327 1328 rtnl_unlock(); 1329 } else { 1330 for (i = 0; i < data->ac_event.num_entries; i++) { 1331 struct qeth_ipacmd_addr_change_entry *entry = 1332 &data->ac_event.entry[i]; 1333 qeth_l2_dev2br_fdb_notify(card, 1334 entry->change_code, 1335 &entry->token, 1336 &entry->addr_lnid); 1337 } 1338 } 1339 1340 free: 1341 kfree(data); 1342 } 1343 1344 static void qeth_addr_change_event_worker(struct work_struct *work) 1345 { 1346 struct delayed_work *dwork = to_delayed_work(work); 1347 struct qeth_addr_change_data *data; 1348 struct qeth_card *card; 1349 int i; 1350 1351 data = container_of(dwork, struct qeth_addr_change_data, dwork); 1352 card = data->card; 1353 1354 QETH_CARD_TEXT(data->card, 4, "adrchgew"); 1355 1356 if (READ_ONCE(card->info.pnso_mode) == QETH_PNSO_NONE) 1357 goto free; 1358 1359 if (data->ac_event.lost_event_mask) { 1360 /* Potential re-config in progress, try again later: */ 1361 if (!mutex_trylock(&card->sbp_lock)) { 1362 queue_delayed_work(card->event_wq, dwork, 1363 msecs_to_jiffies(100)); 1364 return; 1365 } 1366 1367 dev_info(&data->card->gdev->dev, 1368 "Address change notification stopped on %s (%s)\n", 1369 netdev_name(card->dev), 1370 (data->ac_event.lost_event_mask == 0x01) 1371 ? "Overflow" 1372 : (data->ac_event.lost_event_mask == 0x02) 1373 ? "Bridge port state change" 1374 : "Unknown reason"); 1375 1376 data->card->options.sbp.hostnotification = 0; 1377 card->info.pnso_mode = QETH_PNSO_NONE; 1378 mutex_unlock(&data->card->sbp_lock); 1379 qeth_bridge_emit_host_event(data->card, anev_abort, 1380 0, NULL, NULL); 1381 } else 1382 for (i = 0; i < data->ac_event.num_entries; i++) { 1383 struct qeth_ipacmd_addr_change_entry *entry = 1384 &data->ac_event.entry[i]; 1385 qeth_bridge_emit_host_event(data->card, 1386 anev_reg_unreg, 1387 entry->change_code, 1388 &entry->token, 1389 &entry->addr_lnid); 1390 } 1391 1392 free: 1393 kfree(data); 1394 } 1395 1396 static void qeth_addr_change_event(struct qeth_card *card, 1397 struct qeth_ipa_cmd *cmd) 1398 { 1399 struct qeth_ipacmd_addr_change *hostevs = 1400 &cmd->data.addrchange; 1401 struct qeth_addr_change_data *data; 1402 int extrasize; 1403 1404 if (card->info.pnso_mode == QETH_PNSO_NONE) 1405 return; 1406 1407 QETH_CARD_TEXT(card, 4, "adrchgev"); 1408 if (cmd->hdr.return_code != 0x0000) { 1409 if (cmd->hdr.return_code == 0x0010) { 1410 if (hostevs->lost_event_mask == 0x00) 1411 hostevs->lost_event_mask = 0xff; 1412 } else { 1413 QETH_CARD_TEXT_(card, 2, "ACHN%04x", 1414 cmd->hdr.return_code); 1415 return; 1416 } 1417 } 1418 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) * 1419 hostevs->num_entries; 1420 data = kzalloc(sizeof(struct qeth_addr_change_data) + extrasize, 1421 GFP_ATOMIC); 1422 if (!data) { 1423 QETH_CARD_TEXT(card, 2, "ACNalloc"); 1424 return; 1425 } 1426 if (card->info.pnso_mode == QETH_PNSO_BRIDGEPORT) 1427 INIT_DELAYED_WORK(&data->dwork, qeth_addr_change_event_worker); 1428 else 1429 INIT_DELAYED_WORK(&data->dwork, qeth_l2_dev2br_worker); 1430 data->card = card; 1431 memcpy(&data->ac_event, hostevs, 1432 sizeof(struct qeth_ipacmd_addr_change) + extrasize); 1433 queue_delayed_work(card->event_wq, &data->dwork, 0); 1434 } 1435 1436 /* SETBRIDGEPORT support; sending commands */ 1437 1438 struct _qeth_sbp_cbctl { 1439 union { 1440 u32 supported; 1441 struct { 1442 enum qeth_sbp_roles *role; 1443 enum qeth_sbp_states *state; 1444 } qports; 1445 } data; 1446 }; 1447 1448 static int qeth_bridgeport_makerc(struct qeth_card *card, 1449 struct qeth_ipa_cmd *cmd) 1450 { 1451 struct qeth_ipacmd_setbridgeport *sbp = &cmd->data.sbp; 1452 enum qeth_ipa_sbp_cmd setcmd = sbp->hdr.command_code; 1453 u16 ipa_rc = cmd->hdr.return_code; 1454 u16 sbp_rc = sbp->hdr.return_code; 1455 int rc; 1456 1457 if (ipa_rc == IPA_RC_SUCCESS && sbp_rc == IPA_RC_SUCCESS) 1458 return 0; 1459 1460 if ((IS_IQD(card) && ipa_rc == IPA_RC_SUCCESS) || 1461 (!IS_IQD(card) && ipa_rc == sbp_rc)) { 1462 switch (sbp_rc) { 1463 case IPA_RC_SUCCESS: 1464 rc = 0; 1465 break; 1466 case IPA_RC_L2_UNSUPPORTED_CMD: 1467 case IPA_RC_UNSUPPORTED_COMMAND: 1468 rc = -EOPNOTSUPP; 1469 break; 1470 case IPA_RC_SBP_OSA_NOT_CONFIGURED: 1471 case IPA_RC_SBP_IQD_NOT_CONFIGURED: 1472 rc = -ENODEV; /* maybe not the best code here? */ 1473 dev_err(&card->gdev->dev, 1474 "The device is not configured as a Bridge Port\n"); 1475 break; 1476 case IPA_RC_SBP_OSA_OS_MISMATCH: 1477 case IPA_RC_SBP_IQD_OS_MISMATCH: 1478 rc = -EPERM; 1479 dev_err(&card->gdev->dev, 1480 "A Bridge Port is already configured by a different operating system\n"); 1481 break; 1482 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY: 1483 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY: 1484 switch (setcmd) { 1485 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT: 1486 rc = -EEXIST; 1487 dev_err(&card->gdev->dev, 1488 "The LAN already has a primary Bridge Port\n"); 1489 break; 1490 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT: 1491 rc = -EBUSY; 1492 dev_err(&card->gdev->dev, 1493 "The device is already a primary Bridge Port\n"); 1494 break; 1495 default: 1496 rc = -EIO; 1497 } 1498 break; 1499 case IPA_RC_SBP_OSA_CURRENT_SECOND: 1500 case IPA_RC_SBP_IQD_CURRENT_SECOND: 1501 rc = -EBUSY; 1502 dev_err(&card->gdev->dev, 1503 "The device is already a secondary Bridge Port\n"); 1504 break; 1505 case IPA_RC_SBP_OSA_LIMIT_SECOND: 1506 case IPA_RC_SBP_IQD_LIMIT_SECOND: 1507 rc = -EEXIST; 1508 dev_err(&card->gdev->dev, 1509 "The LAN cannot have more secondary Bridge Ports\n"); 1510 break; 1511 case IPA_RC_SBP_OSA_CURRENT_PRIMARY: 1512 case IPA_RC_SBP_IQD_CURRENT_PRIMARY: 1513 rc = -EBUSY; 1514 dev_err(&card->gdev->dev, 1515 "The device is already a primary Bridge Port\n"); 1516 break; 1517 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN: 1518 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN: 1519 rc = -EACCES; 1520 dev_err(&card->gdev->dev, 1521 "The device is not authorized to be a Bridge Port\n"); 1522 break; 1523 default: 1524 rc = -EIO; 1525 } 1526 } else { 1527 switch (ipa_rc) { 1528 case IPA_RC_NOTSUPP: 1529 rc = -EOPNOTSUPP; 1530 break; 1531 case IPA_RC_UNSUPPORTED_COMMAND: 1532 rc = -EOPNOTSUPP; 1533 break; 1534 default: 1535 rc = -EIO; 1536 } 1537 } 1538 1539 if (rc) { 1540 QETH_CARD_TEXT_(card, 2, "SBPi%04x", ipa_rc); 1541 QETH_CARD_TEXT_(card, 2, "SBPc%04x", sbp_rc); 1542 } 1543 return rc; 1544 } 1545 1546 static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card, 1547 enum qeth_ipa_sbp_cmd sbp_cmd, 1548 unsigned int data_length) 1549 { 1550 enum qeth_ipa_cmds ipa_cmd = IS_IQD(card) ? IPA_CMD_SETBRIDGEPORT_IQD : 1551 IPA_CMD_SETBRIDGEPORT_OSA; 1552 struct qeth_ipacmd_sbp_hdr *hdr; 1553 struct qeth_cmd_buffer *iob; 1554 1555 iob = qeth_ipa_alloc_cmd(card, ipa_cmd, QETH_PROT_NONE, 1556 data_length + 1557 offsetof(struct qeth_ipacmd_setbridgeport, 1558 data)); 1559 if (!iob) 1560 return iob; 1561 1562 hdr = &__ipa_cmd(iob)->data.sbp.hdr; 1563 hdr->cmdlength = sizeof(*hdr) + data_length; 1564 hdr->command_code = sbp_cmd; 1565 hdr->used_total = 1; 1566 hdr->seq_no = 1; 1567 return iob; 1568 } 1569 1570 static int qeth_bridgeport_query_support_cb(struct qeth_card *card, 1571 struct qeth_reply *reply, unsigned long data) 1572 { 1573 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1574 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; 1575 int rc; 1576 1577 QETH_CARD_TEXT(card, 2, "brqsupcb"); 1578 rc = qeth_bridgeport_makerc(card, cmd); 1579 if (rc) 1580 return rc; 1581 1582 cbctl->data.supported = 1583 cmd->data.sbp.data.query_cmds_supp.supported_cmds; 1584 return 0; 1585 } 1586 1587 /** 1588 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions. 1589 * @card: qeth_card structure pointer. 1590 * 1591 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card 1592 * strucutre: card->options.sbp.supported_funcs. 1593 */ 1594 static void qeth_bridgeport_query_support(struct qeth_card *card) 1595 { 1596 struct qeth_cmd_buffer *iob; 1597 struct _qeth_sbp_cbctl cbctl; 1598 1599 QETH_CARD_TEXT(card, 2, "brqsuppo"); 1600 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED, 1601 SBP_DATA_SIZEOF(query_cmds_supp)); 1602 if (!iob) 1603 return; 1604 1605 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb, 1606 &cbctl)) { 1607 card->options.sbp.role = QETH_SBP_ROLE_NONE; 1608 card->options.sbp.supported_funcs = 0; 1609 return; 1610 } 1611 card->options.sbp.supported_funcs = cbctl.data.supported; 1612 } 1613 1614 static int qeth_bridgeport_query_ports_cb(struct qeth_card *card, 1615 struct qeth_reply *reply, unsigned long data) 1616 { 1617 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1618 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; 1619 struct qeth_sbp_port_data *qports; 1620 int rc; 1621 1622 QETH_CARD_TEXT(card, 2, "brqprtcb"); 1623 rc = qeth_bridgeport_makerc(card, cmd); 1624 if (rc) 1625 return rc; 1626 1627 qports = &cmd->data.sbp.data.port_data; 1628 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { 1629 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length); 1630 return -EINVAL; 1631 } 1632 /* first entry contains the state of the local port */ 1633 if (qports->num_entries > 0) { 1634 if (cbctl->data.qports.role) 1635 *cbctl->data.qports.role = qports->entry[0].role; 1636 if (cbctl->data.qports.state) 1637 *cbctl->data.qports.state = qports->entry[0].state; 1638 } 1639 return 0; 1640 } 1641 1642 /** 1643 * qeth_bridgeport_query_ports() - query local bridgeport status. 1644 * @card: qeth_card structure pointer. 1645 * @role: Role of the port: 0-none, 1-primary, 2-secondary. 1646 * @state: State of the port: 0-inactive, 1-standby, 2-active. 1647 * 1648 * Returns negative errno-compatible error indication or 0 on success. 1649 * 1650 * 'role' and 'state' are not updated in case of hardware operation failure. 1651 */ 1652 int qeth_bridgeport_query_ports(struct qeth_card *card, 1653 enum qeth_sbp_roles *role, enum qeth_sbp_states *state) 1654 { 1655 struct qeth_cmd_buffer *iob; 1656 struct _qeth_sbp_cbctl cbctl = { 1657 .data = { 1658 .qports = { 1659 .role = role, 1660 .state = state, 1661 }, 1662 }, 1663 }; 1664 1665 QETH_CARD_TEXT(card, 2, "brqports"); 1666 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS)) 1667 return -EOPNOTSUPP; 1668 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0); 1669 if (!iob) 1670 return -ENOMEM; 1671 1672 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb, 1673 &cbctl); 1674 } 1675 1676 static int qeth_bridgeport_set_cb(struct qeth_card *card, 1677 struct qeth_reply *reply, unsigned long data) 1678 { 1679 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data; 1680 1681 QETH_CARD_TEXT(card, 2, "brsetrcb"); 1682 return qeth_bridgeport_makerc(card, cmd); 1683 } 1684 1685 /** 1686 * qeth_bridgeport_setrole() - Assign primary role to the port. 1687 * @card: qeth_card structure pointer. 1688 * @role: Role to assign. 1689 * 1690 * Returns negative errno-compatible error indication or 0 on success. 1691 */ 1692 int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role) 1693 { 1694 struct qeth_cmd_buffer *iob; 1695 enum qeth_ipa_sbp_cmd setcmd; 1696 unsigned int cmdlength = 0; 1697 1698 QETH_CARD_TEXT(card, 2, "brsetrol"); 1699 switch (role) { 1700 case QETH_SBP_ROLE_NONE: 1701 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE; 1702 break; 1703 case QETH_SBP_ROLE_PRIMARY: 1704 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT; 1705 cmdlength = SBP_DATA_SIZEOF(set_primary); 1706 break; 1707 case QETH_SBP_ROLE_SECONDARY: 1708 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT; 1709 break; 1710 default: 1711 return -EINVAL; 1712 } 1713 if (!(card->options.sbp.supported_funcs & setcmd)) 1714 return -EOPNOTSUPP; 1715 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength); 1716 if (!iob) 1717 return -ENOMEM; 1718 1719 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, NULL); 1720 } 1721 1722 static void qeth_bridgeport_an_set_cb(void *priv, 1723 struct chsc_pnso_naid_l2 *entry) 1724 { 1725 struct qeth_card *card = (struct qeth_card *)priv; 1726 u8 code; 1727 1728 code = IPA_ADDR_CHANGE_CODE_MACADDR; 1729 if (entry->addr_lnid.lnid < VLAN_N_VID) 1730 code |= IPA_ADDR_CHANGE_CODE_VLANID; 1731 qeth_bridge_emit_host_event(card, anev_reg_unreg, code, 1732 (struct net_if_token *)&entry->nit, 1733 (struct mac_addr_lnid *)&entry->addr_lnid); 1734 } 1735 1736 /** 1737 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification 1738 * @card: qeth_card structure pointer. 1739 * @enable: 0 - disable, non-zero - enable notifications 1740 * 1741 * Returns negative errno-compatible error indication or 0 on success. 1742 * 1743 * On enable, emits a series of address notifications udev events for all 1744 * currently registered hosts. 1745 */ 1746 int qeth_bridgeport_an_set(struct qeth_card *card, int enable) 1747 { 1748 int rc; 1749 1750 if (!card->options.sbp.supported_funcs) 1751 return -EOPNOTSUPP; 1752 1753 if (enable) { 1754 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL); 1755 qeth_l2_set_pnso_mode(card, QETH_PNSO_BRIDGEPORT); 1756 rc = qeth_l2_pnso(card, PNSO_OC_NET_BRIDGE_INFO, 1, 1757 qeth_bridgeport_an_set_cb, card); 1758 if (rc) 1759 qeth_l2_set_pnso_mode(card, QETH_PNSO_NONE); 1760 } else { 1761 rc = qeth_l2_pnso(card, PNSO_OC_NET_BRIDGE_INFO, 0, NULL, NULL); 1762 qeth_l2_set_pnso_mode(card, QETH_PNSO_NONE); 1763 } 1764 return rc; 1765 } 1766 1767 /* VNIC Characteristics support */ 1768 1769 /* handle VNICC IPA command return codes; convert to error codes */ 1770 static int qeth_l2_vnicc_makerc(struct qeth_card *card, u16 ipa_rc) 1771 { 1772 int rc; 1773 1774 switch (ipa_rc) { 1775 case IPA_RC_SUCCESS: 1776 return ipa_rc; 1777 case IPA_RC_L2_UNSUPPORTED_CMD: 1778 case IPA_RC_NOTSUPP: 1779 rc = -EOPNOTSUPP; 1780 break; 1781 case IPA_RC_VNICC_OOSEQ: 1782 rc = -EALREADY; 1783 break; 1784 case IPA_RC_VNICC_VNICBP: 1785 rc = -EBUSY; 1786 break; 1787 case IPA_RC_L2_ADDR_TABLE_FULL: 1788 rc = -ENOSPC; 1789 break; 1790 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: 1791 rc = -EACCES; 1792 break; 1793 default: 1794 rc = -EIO; 1795 } 1796 1797 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc); 1798 return rc; 1799 } 1800 1801 /* generic VNICC request call back */ 1802 static int qeth_l2_vnicc_request_cb(struct qeth_card *card, 1803 struct qeth_reply *reply, 1804 unsigned long data) 1805 { 1806 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1807 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc; 1808 u32 sub_cmd = cmd->data.vnicc.hdr.sub_command; 1809 1810 QETH_CARD_TEXT(card, 2, "vniccrcb"); 1811 if (cmd->hdr.return_code) 1812 return qeth_l2_vnicc_makerc(card, cmd->hdr.return_code); 1813 /* return results to caller */ 1814 card->options.vnicc.sup_chars = rep->vnicc_cmds.supported; 1815 card->options.vnicc.cur_chars = rep->vnicc_cmds.enabled; 1816 1817 if (sub_cmd == IPA_VNICC_QUERY_CMDS) 1818 *(u32 *)reply->param = rep->data.query_cmds.sup_cmds; 1819 else if (sub_cmd == IPA_VNICC_GET_TIMEOUT) 1820 *(u32 *)reply->param = rep->data.getset_timeout.timeout; 1821 1822 return 0; 1823 } 1824 1825 static struct qeth_cmd_buffer *qeth_l2_vnicc_build_cmd(struct qeth_card *card, 1826 u32 vnicc_cmd, 1827 unsigned int data_length) 1828 { 1829 struct qeth_ipacmd_vnicc_hdr *hdr; 1830 struct qeth_cmd_buffer *iob; 1831 1832 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_VNICC, QETH_PROT_NONE, 1833 data_length + 1834 offsetof(struct qeth_ipacmd_vnicc, data)); 1835 if (!iob) 1836 return NULL; 1837 1838 hdr = &__ipa_cmd(iob)->data.vnicc.hdr; 1839 hdr->data_length = sizeof(*hdr) + data_length; 1840 hdr->sub_command = vnicc_cmd; 1841 return iob; 1842 } 1843 1844 /* VNICC query VNIC characteristics request */ 1845 static int qeth_l2_vnicc_query_chars(struct qeth_card *card) 1846 { 1847 struct qeth_cmd_buffer *iob; 1848 1849 QETH_CARD_TEXT(card, 2, "vniccqch"); 1850 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CHARS, 0); 1851 if (!iob) 1852 return -ENOMEM; 1853 1854 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL); 1855 } 1856 1857 /* VNICC query sub commands request */ 1858 static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char, 1859 u32 *sup_cmds) 1860 { 1861 struct qeth_cmd_buffer *iob; 1862 1863 QETH_CARD_TEXT(card, 2, "vniccqcm"); 1864 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CMDS, 1865 VNICC_DATA_SIZEOF(query_cmds)); 1866 if (!iob) 1867 return -ENOMEM; 1868 1869 __ipa_cmd(iob)->data.vnicc.data.query_cmds.vnic_char = vnic_char; 1870 1871 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, sup_cmds); 1872 } 1873 1874 /* VNICC enable/disable characteristic request */ 1875 static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char, 1876 u32 cmd) 1877 { 1878 struct qeth_cmd_buffer *iob; 1879 1880 QETH_CARD_TEXT(card, 2, "vniccedc"); 1881 iob = qeth_l2_vnicc_build_cmd(card, cmd, VNICC_DATA_SIZEOF(set_char)); 1882 if (!iob) 1883 return -ENOMEM; 1884 1885 __ipa_cmd(iob)->data.vnicc.data.set_char.vnic_char = vnic_char; 1886 1887 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL); 1888 } 1889 1890 /* VNICC get/set timeout for characteristic request */ 1891 static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc, 1892 u32 cmd, u32 *timeout) 1893 { 1894 struct qeth_vnicc_getset_timeout *getset_timeout; 1895 struct qeth_cmd_buffer *iob; 1896 1897 QETH_CARD_TEXT(card, 2, "vniccgst"); 1898 iob = qeth_l2_vnicc_build_cmd(card, cmd, 1899 VNICC_DATA_SIZEOF(getset_timeout)); 1900 if (!iob) 1901 return -ENOMEM; 1902 1903 getset_timeout = &__ipa_cmd(iob)->data.vnicc.data.getset_timeout; 1904 getset_timeout->vnic_char = vnicc; 1905 1906 if (cmd == IPA_VNICC_SET_TIMEOUT) 1907 getset_timeout->timeout = *timeout; 1908 1909 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, timeout); 1910 } 1911 1912 /* recover user timeout setting */ 1913 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc, 1914 u32 *timeout) 1915 { 1916 if (card->options.vnicc.sup_chars & vnicc && 1917 card->options.vnicc.getset_timeout_sup & vnicc && 1918 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT, 1919 timeout)) 1920 return false; 1921 *timeout = QETH_VNICC_DEFAULT_TIMEOUT; 1922 return true; 1923 } 1924 1925 /* set current VNICC flag state; called from sysfs store function */ 1926 int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state) 1927 { 1928 int rc = 0; 1929 u32 cmd; 1930 1931 QETH_CARD_TEXT(card, 2, "vniccsch"); 1932 1933 /* check if characteristic and enable/disable are supported */ 1934 if (!(card->options.vnicc.sup_chars & vnicc) || 1935 !(card->options.vnicc.set_char_sup & vnicc)) 1936 return -EOPNOTSUPP; 1937 1938 if (qeth_bridgeport_is_in_use(card)) 1939 return -EBUSY; 1940 1941 /* set enable/disable command and store wanted characteristic */ 1942 if (state) { 1943 cmd = IPA_VNICC_ENABLE; 1944 card->options.vnicc.wanted_chars |= vnicc; 1945 } else { 1946 cmd = IPA_VNICC_DISABLE; 1947 card->options.vnicc.wanted_chars &= ~vnicc; 1948 } 1949 1950 /* do we need to do anything? */ 1951 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars) 1952 return rc; 1953 1954 /* if card is not ready, simply stop here */ 1955 if (!qeth_card_hw_is_reachable(card)) { 1956 if (state) 1957 card->options.vnicc.cur_chars |= vnicc; 1958 else 1959 card->options.vnicc.cur_chars &= ~vnicc; 1960 return rc; 1961 } 1962 1963 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd); 1964 if (rc) 1965 card->options.vnicc.wanted_chars = 1966 card->options.vnicc.cur_chars; 1967 else { 1968 /* successful online VNICC change; handle special cases */ 1969 if (state && vnicc == QETH_VNICC_RX_BCAST) 1970 card->options.vnicc.rx_bcast_enabled = true; 1971 if (!state && vnicc == QETH_VNICC_LEARNING) 1972 qeth_l2_vnicc_recover_timeout(card, vnicc, 1973 &card->options.vnicc.learning_timeout); 1974 } 1975 1976 return rc; 1977 } 1978 1979 /* get current VNICC flag state; called from sysfs show function */ 1980 int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state) 1981 { 1982 int rc = 0; 1983 1984 QETH_CARD_TEXT(card, 2, "vniccgch"); 1985 1986 /* check if characteristic is supported */ 1987 if (!(card->options.vnicc.sup_chars & vnicc)) 1988 return -EOPNOTSUPP; 1989 1990 if (qeth_bridgeport_is_in_use(card)) 1991 return -EBUSY; 1992 1993 /* if card is ready, query current VNICC state */ 1994 if (qeth_card_hw_is_reachable(card)) 1995 rc = qeth_l2_vnicc_query_chars(card); 1996 1997 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false; 1998 return rc; 1999 } 2000 2001 /* set VNICC timeout; called from sysfs store function. Currently, only learning 2002 * supports timeout 2003 */ 2004 int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout) 2005 { 2006 int rc = 0; 2007 2008 QETH_CARD_TEXT(card, 2, "vniccsto"); 2009 2010 /* check if characteristic and set_timeout are supported */ 2011 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) || 2012 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING)) 2013 return -EOPNOTSUPP; 2014 2015 if (qeth_bridgeport_is_in_use(card)) 2016 return -EBUSY; 2017 2018 /* do we need to do anything? */ 2019 if (card->options.vnicc.learning_timeout == timeout) 2020 return rc; 2021 2022 /* if card is not ready, simply store the value internally and return */ 2023 if (!qeth_card_hw_is_reachable(card)) { 2024 card->options.vnicc.learning_timeout = timeout; 2025 return rc; 2026 } 2027 2028 /* send timeout value to card; if successful, store value internally */ 2029 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING, 2030 IPA_VNICC_SET_TIMEOUT, &timeout); 2031 if (!rc) 2032 card->options.vnicc.learning_timeout = timeout; 2033 2034 return rc; 2035 } 2036 2037 /* get current VNICC timeout; called from sysfs show function. Currently, only 2038 * learning supports timeout 2039 */ 2040 int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout) 2041 { 2042 int rc = 0; 2043 2044 QETH_CARD_TEXT(card, 2, "vniccgto"); 2045 2046 /* check if characteristic and get_timeout are supported */ 2047 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) || 2048 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING)) 2049 return -EOPNOTSUPP; 2050 2051 if (qeth_bridgeport_is_in_use(card)) 2052 return -EBUSY; 2053 2054 /* if card is ready, get timeout. Otherwise, just return stored value */ 2055 *timeout = card->options.vnicc.learning_timeout; 2056 if (qeth_card_hw_is_reachable(card)) 2057 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING, 2058 IPA_VNICC_GET_TIMEOUT, 2059 timeout); 2060 2061 return rc; 2062 } 2063 2064 /* check if VNICC is currently enabled */ 2065 static bool _qeth_l2_vnicc_is_in_use(struct qeth_card *card) 2066 { 2067 if (!card->options.vnicc.sup_chars) 2068 return false; 2069 /* default values are only OK if rx_bcast was not enabled by user 2070 * or the card is offline. 2071 */ 2072 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) { 2073 if (!card->options.vnicc.rx_bcast_enabled || 2074 !qeth_card_hw_is_reachable(card)) 2075 return false; 2076 } 2077 return true; 2078 } 2079 2080 /** 2081 * qeth_bridgeport_allowed - are any qeth_bridgeport functions allowed? 2082 * @card: qeth_card structure pointer 2083 * 2084 * qeth_bridgeport functionality is mutually exclusive with usage of the 2085 * VNIC Characteristics and dev2br address notifications 2086 */ 2087 bool qeth_bridgeport_allowed(struct qeth_card *card) 2088 { 2089 struct qeth_priv *priv = netdev_priv(card->dev); 2090 2091 return (!_qeth_l2_vnicc_is_in_use(card) && 2092 !(priv->brport_features & BR_LEARNING_SYNC)); 2093 } 2094 2095 /* recover user characteristic setting */ 2096 static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc, 2097 bool enable) 2098 { 2099 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE; 2100 2101 if (card->options.vnicc.sup_chars & vnicc && 2102 card->options.vnicc.set_char_sup & vnicc && 2103 !qeth_l2_vnicc_set_char(card, vnicc, cmd)) 2104 return false; 2105 card->options.vnicc.wanted_chars &= ~vnicc; 2106 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc; 2107 return true; 2108 } 2109 2110 /* (re-)initialize VNICC */ 2111 static void qeth_l2_vnicc_init(struct qeth_card *card) 2112 { 2113 u32 *timeout = &card->options.vnicc.learning_timeout; 2114 bool enable, error = false; 2115 unsigned int chars_len, i; 2116 unsigned long chars_tmp; 2117 u32 sup_cmds, vnicc; 2118 2119 QETH_CARD_TEXT(card, 2, "vniccini"); 2120 /* reset rx_bcast */ 2121 card->options.vnicc.rx_bcast_enabled = 0; 2122 /* initial query and storage of VNIC characteristics */ 2123 if (qeth_l2_vnicc_query_chars(card)) { 2124 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT || 2125 *timeout != QETH_VNICC_DEFAULT_TIMEOUT) 2126 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n"); 2127 /* fail quietly if user didn't change the default config */ 2128 card->options.vnicc.sup_chars = 0; 2129 card->options.vnicc.cur_chars = 0; 2130 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT; 2131 return; 2132 } 2133 /* get supported commands for each supported characteristic */ 2134 chars_tmp = card->options.vnicc.sup_chars; 2135 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE; 2136 for_each_set_bit(i, &chars_tmp, chars_len) { 2137 vnicc = BIT(i); 2138 if (qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds)) { 2139 sup_cmds = 0; 2140 error = true; 2141 } 2142 if ((sup_cmds & IPA_VNICC_SET_TIMEOUT) && 2143 (sup_cmds & IPA_VNICC_GET_TIMEOUT)) 2144 card->options.vnicc.getset_timeout_sup |= vnicc; 2145 else 2146 card->options.vnicc.getset_timeout_sup &= ~vnicc; 2147 if ((sup_cmds & IPA_VNICC_ENABLE) && 2148 (sup_cmds & IPA_VNICC_DISABLE)) 2149 card->options.vnicc.set_char_sup |= vnicc; 2150 else 2151 card->options.vnicc.set_char_sup &= ~vnicc; 2152 } 2153 /* enforce assumed default values and recover settings, if changed */ 2154 error |= qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING, 2155 timeout); 2156 /* Change chars, if necessary */ 2157 chars_tmp = card->options.vnicc.wanted_chars ^ 2158 card->options.vnicc.cur_chars; 2159 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE; 2160 for_each_set_bit(i, &chars_tmp, chars_len) { 2161 vnicc = BIT(i); 2162 enable = card->options.vnicc.wanted_chars & vnicc; 2163 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable); 2164 } 2165 if (error) 2166 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n"); 2167 } 2168 2169 /* configure default values of VNIC characteristics */ 2170 static void qeth_l2_vnicc_set_defaults(struct qeth_card *card) 2171 { 2172 /* characteristics values */ 2173 card->options.vnicc.sup_chars = QETH_VNICC_ALL; 2174 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT; 2175 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT; 2176 /* supported commands */ 2177 card->options.vnicc.set_char_sup = QETH_VNICC_ALL; 2178 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING; 2179 /* settings wanted by users */ 2180 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT; 2181 } 2182 2183 static const struct device_type qeth_l2_devtype = { 2184 .name = "qeth_layer2", 2185 .groups = qeth_l2_attr_groups, 2186 }; 2187 2188 static int qeth_l2_probe_device(struct ccwgroup_device *gdev) 2189 { 2190 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 2191 int rc; 2192 2193 if (IS_OSN(card)) 2194 dev_notice(&gdev->dev, "OSN support will be dropped in 2021\n"); 2195 2196 qeth_l2_vnicc_set_defaults(card); 2197 mutex_init(&card->sbp_lock); 2198 2199 if (gdev->dev.type == &qeth_generic_devtype) { 2200 rc = device_add_groups(&gdev->dev, qeth_l2_attr_groups); 2201 if (rc) 2202 return rc; 2203 } 2204 2205 INIT_WORK(&card->rx_mode_work, qeth_l2_rx_mode_work); 2206 return 0; 2207 } 2208 2209 static void qeth_l2_remove_device(struct ccwgroup_device *gdev) 2210 { 2211 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 2212 2213 if (gdev->dev.type == &qeth_generic_devtype) 2214 device_remove_groups(&gdev->dev, qeth_l2_attr_groups); 2215 qeth_set_allowed_threads(card, 0, 1); 2216 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); 2217 2218 if (gdev->state == CCWGROUP_ONLINE) 2219 qeth_set_offline(card, card->discipline, false); 2220 2221 cancel_work_sync(&card->close_dev_work); 2222 if (card->dev->reg_state == NETREG_REGISTERED) 2223 unregister_netdev(card->dev); 2224 } 2225 2226 static int qeth_l2_set_online(struct qeth_card *card, bool carrier_ok) 2227 { 2228 struct net_device *dev = card->dev; 2229 int rc = 0; 2230 2231 qeth_l2_detect_dev2br_support(card); 2232 2233 mutex_lock(&card->sbp_lock); 2234 qeth_bridgeport_query_support(card); 2235 if (card->options.sbp.supported_funcs) { 2236 qeth_l2_setup_bridgeport_attrs(card); 2237 dev_info(&card->gdev->dev, 2238 "The device represents a Bridge Capable Port\n"); 2239 } 2240 mutex_unlock(&card->sbp_lock); 2241 2242 qeth_l2_register_dev_addr(card); 2243 2244 /* for the rx_bcast characteristic, init VNICC after setmac */ 2245 qeth_l2_vnicc_init(card); 2246 2247 qeth_l2_trace_features(card); 2248 2249 /* softsetup */ 2250 QETH_CARD_TEXT(card, 2, "softsetp"); 2251 2252 card->state = CARD_STATE_SOFTSETUP; 2253 2254 qeth_set_allowed_threads(card, 0xffffffff, 0); 2255 2256 if (dev->reg_state != NETREG_REGISTERED) { 2257 rc = qeth_l2_setup_netdev(card); 2258 if (rc) 2259 goto err_setup; 2260 2261 if (carrier_ok) 2262 netif_carrier_on(dev); 2263 } else { 2264 rtnl_lock(); 2265 rc = qeth_set_real_num_tx_queues(card, 2266 qeth_tx_actual_queues(card)); 2267 if (rc) { 2268 rtnl_unlock(); 2269 goto err_set_queues; 2270 } 2271 2272 if (carrier_ok) 2273 netif_carrier_on(dev); 2274 else 2275 netif_carrier_off(dev); 2276 2277 netif_device_attach(dev); 2278 qeth_enable_hw_features(dev); 2279 qeth_l2_enable_brport_features(card); 2280 2281 if (card->info.open_when_online) { 2282 card->info.open_when_online = 0; 2283 dev_open(dev, NULL); 2284 } 2285 rtnl_unlock(); 2286 } 2287 return 0; 2288 2289 err_set_queues: 2290 err_setup: 2291 qeth_set_allowed_threads(card, 0, 1); 2292 card->state = CARD_STATE_DOWN; 2293 return rc; 2294 } 2295 2296 static void qeth_l2_set_offline(struct qeth_card *card) 2297 { 2298 struct qeth_priv *priv = netdev_priv(card->dev); 2299 2300 qeth_set_allowed_threads(card, 0, 1); 2301 qeth_l2_drain_rx_mode_cache(card); 2302 2303 if (card->state == CARD_STATE_SOFTSETUP) 2304 card->state = CARD_STATE_DOWN; 2305 2306 qeth_l2_set_pnso_mode(card, QETH_PNSO_NONE); 2307 if (priv->brport_features & BR_LEARNING_SYNC) 2308 qeth_l2_dev2br_fdb_flush(card); 2309 } 2310 2311 /* Returns zero if the command is successfully "consumed" */ 2312 static int qeth_l2_control_event(struct qeth_card *card, 2313 struct qeth_ipa_cmd *cmd) 2314 { 2315 switch (cmd->hdr.command) { 2316 case IPA_CMD_SETBRIDGEPORT_OSA: 2317 case IPA_CMD_SETBRIDGEPORT_IQD: 2318 if (cmd->data.sbp.hdr.command_code == 2319 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) { 2320 qeth_bridge_state_change(card, cmd); 2321 return 0; 2322 } 2323 2324 return 1; 2325 case IPA_CMD_ADDRESS_CHANGE_NOTIF: 2326 qeth_addr_change_event(card, cmd); 2327 return 0; 2328 default: 2329 return 1; 2330 } 2331 } 2332 2333 const struct qeth_discipline qeth_l2_discipline = { 2334 .devtype = &qeth_l2_devtype, 2335 .setup = qeth_l2_probe_device, 2336 .remove = qeth_l2_remove_device, 2337 .set_online = qeth_l2_set_online, 2338 .set_offline = qeth_l2_set_offline, 2339 .do_ioctl = NULL, 2340 .control_event_handler = qeth_l2_control_event, 2341 }; 2342 EXPORT_SYMBOL_GPL(qeth_l2_discipline); 2343 2344 static int __init qeth_l2_init(void) 2345 { 2346 pr_info("register layer 2 discipline\n"); 2347 return 0; 2348 } 2349 2350 static void __exit qeth_l2_exit(void) 2351 { 2352 pr_info("unregister layer 2 discipline\n"); 2353 } 2354 2355 module_init(qeth_l2_init); 2356 module_exit(qeth_l2_exit); 2357 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); 2358 MODULE_DESCRIPTION("qeth layer 2 discipline"); 2359 MODULE_LICENSE("GPL"); 2360