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