1 /* 2 * Copyright IBM Corp. 2007, 2009 3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>, 4 * Frank Pavlic <fpavlic@de.ibm.com>, 5 * Thomas Spatzier <tspat@de.ibm.com>, 6 * Frank Blaschka <frank.blaschka@de.ibm.com> 7 */ 8 9 #define KMSG_COMPONENT "qeth" 10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 11 12 #include <linux/module.h> 13 #include <linux/moduleparam.h> 14 #include <linux/string.h> 15 #include <linux/errno.h> 16 #include <linux/kernel.h> 17 #include <linux/slab.h> 18 #include <linux/etherdevice.h> 19 #include <linux/ip.h> 20 #include <linux/list.h> 21 #include <linux/hash.h> 22 #include <linux/hashtable.h> 23 #include <linux/string.h> 24 #include <asm/setup.h> 25 #include "qeth_core.h" 26 #include "qeth_l2.h" 27 28 static int qeth_l2_set_offline(struct ccwgroup_device *); 29 static int qeth_l2_stop(struct net_device *); 30 static void qeth_l2_set_rx_mode(struct net_device *); 31 static void qeth_bridgeport_query_support(struct qeth_card *card); 32 static void qeth_bridge_state_change(struct qeth_card *card, 33 struct qeth_ipa_cmd *cmd); 34 static void qeth_bridge_host_event(struct qeth_card *card, 35 struct qeth_ipa_cmd *cmd); 36 37 static int qeth_l2_verify_dev(struct net_device *dev) 38 { 39 struct qeth_card *card; 40 unsigned long flags; 41 int rc = 0; 42 43 read_lock_irqsave(&qeth_core_card_list.rwlock, flags); 44 list_for_each_entry(card, &qeth_core_card_list.list, list) { 45 if (card->dev == dev) { 46 rc = QETH_REAL_CARD; 47 break; 48 } 49 } 50 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); 51 52 return rc; 53 } 54 55 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no) 56 { 57 struct qeth_card *card; 58 struct net_device *ndev; 59 __u16 temp_dev_no; 60 unsigned long flags; 61 struct ccw_dev_id read_devid; 62 63 ndev = NULL; 64 memcpy(&temp_dev_no, read_dev_no, 2); 65 read_lock_irqsave(&qeth_core_card_list.rwlock, flags); 66 list_for_each_entry(card, &qeth_core_card_list.list, list) { 67 ccw_device_get_id(CARD_RDEV(card), &read_devid); 68 if (read_devid.devno == temp_dev_no) { 69 ndev = card->dev; 70 break; 71 } 72 } 73 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); 74 return ndev; 75 } 76 77 static int qeth_setdel_makerc(struct qeth_card *card, int retcode) 78 { 79 int rc; 80 81 if (retcode) 82 QETH_CARD_TEXT_(card, 2, "err%04x", retcode); 83 switch (retcode) { 84 case IPA_RC_SUCCESS: 85 rc = 0; 86 break; 87 case IPA_RC_L2_UNSUPPORTED_CMD: 88 rc = -EOPNOTSUPP; 89 break; 90 case IPA_RC_L2_ADDR_TABLE_FULL: 91 rc = -ENOSPC; 92 break; 93 case IPA_RC_L2_DUP_MAC: 94 case IPA_RC_L2_DUP_LAYER3_MAC: 95 rc = -EEXIST; 96 break; 97 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP: 98 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: 99 rc = -EPERM; 100 break; 101 case IPA_RC_L2_MAC_NOT_FOUND: 102 rc = -ENOENT; 103 break; 104 case -ENOMEM: 105 rc = -ENOMEM; 106 break; 107 default: 108 rc = -EIO; 109 break; 110 } 111 return rc; 112 } 113 114 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac, 115 enum qeth_ipa_cmds ipacmd) 116 { 117 struct qeth_ipa_cmd *cmd; 118 struct qeth_cmd_buffer *iob; 119 120 QETH_CARD_TEXT(card, 2, "L2sdmac"); 121 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); 122 if (!iob) 123 return -ENOMEM; 124 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); 125 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN; 126 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN); 127 return qeth_setdel_makerc(card, qeth_send_ipa_cmd(card, iob, 128 NULL, NULL)); 129 } 130 131 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac) 132 { 133 int rc; 134 135 QETH_CARD_TEXT(card, 2, "L2Setmac"); 136 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC); 137 if (rc == 0) { 138 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED; 139 memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN); 140 dev_info(&card->gdev->dev, 141 "MAC address %pM successfully registered on device %s\n", 142 card->dev->dev_addr, card->dev->name); 143 } else { 144 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; 145 switch (rc) { 146 case -EEXIST: 147 dev_warn(&card->gdev->dev, 148 "MAC address %pM already exists\n", mac); 149 break; 150 case -EPERM: 151 dev_warn(&card->gdev->dev, 152 "MAC address %pM is not authorized\n", mac); 153 break; 154 } 155 } 156 return rc; 157 } 158 159 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac) 160 { 161 int rc; 162 163 QETH_CARD_TEXT(card, 2, "L2Delmac"); 164 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)) 165 return 0; 166 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC); 167 if (rc == 0) 168 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; 169 return rc; 170 } 171 172 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac) 173 { 174 int rc; 175 176 QETH_CARD_TEXT(card, 2, "L2Sgmac"); 177 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC); 178 if (rc == -EEXIST) 179 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n", 180 mac, QETH_CARD_IFNAME(card)); 181 else if (rc) 182 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n", 183 mac, QETH_CARD_IFNAME(card), rc); 184 return rc; 185 } 186 187 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac) 188 { 189 int rc; 190 191 QETH_CARD_TEXT(card, 2, "L2Dgmac"); 192 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC); 193 if (rc) 194 QETH_DBF_MESSAGE(2, 195 "Could not delete group MAC %pM on %s: %d\n", 196 mac, QETH_CARD_IFNAME(card), rc); 197 return rc; 198 } 199 200 static int qeth_l2_write_mac(struct qeth_card *card, struct qeth_mac *mac) 201 { 202 if (mac->is_uc) { 203 return qeth_l2_send_setdelmac(card, mac->mac_addr, 204 IPA_CMD_SETVMAC); 205 } else { 206 return qeth_l2_send_setgroupmac(card, mac->mac_addr); 207 } 208 } 209 210 static int qeth_l2_remove_mac(struct qeth_card *card, struct qeth_mac *mac) 211 { 212 if (mac->is_uc) { 213 return qeth_l2_send_setdelmac(card, mac->mac_addr, 214 IPA_CMD_DELVMAC); 215 } else { 216 return qeth_l2_send_delgroupmac(card, mac->mac_addr); 217 } 218 } 219 220 static void qeth_l2_del_all_macs(struct qeth_card *card) 221 { 222 struct qeth_mac *mac; 223 struct hlist_node *tmp; 224 int i; 225 226 spin_lock_bh(&card->mclock); 227 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { 228 hash_del(&mac->hnode); 229 kfree(mac); 230 } 231 spin_unlock_bh(&card->mclock); 232 } 233 234 static inline u32 qeth_l2_mac_hash(const u8 *addr) 235 { 236 return get_unaligned((u32 *)(&addr[2])); 237 } 238 239 static inline int qeth_l2_get_cast_type(struct qeth_card *card, 240 struct sk_buff *skb) 241 { 242 if (card->info.type == QETH_CARD_TYPE_OSN) 243 return RTN_UNSPEC; 244 if (is_broadcast_ether_addr(skb->data)) 245 return RTN_BROADCAST; 246 if (is_multicast_ether_addr(skb->data)) 247 return RTN_MULTICAST; 248 return RTN_UNSPEC; 249 } 250 251 static inline void qeth_l2_hdr_csum(struct qeth_card *card, 252 struct qeth_hdr *hdr, struct sk_buff *skb) 253 { 254 struct iphdr *iph = ip_hdr(skb); 255 256 /* tcph->check contains already the pseudo hdr checksum 257 * so just set the header flags 258 */ 259 if (iph->protocol == IPPROTO_UDP) 260 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP; 261 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ | 262 QETH_HDR_EXT_CSUM_HDR_REQ; 263 iph->check = 0; 264 if (card->options.performance_stats) 265 card->perf_stats.tx_csum++; 266 } 267 268 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, 269 struct sk_buff *skb, int cast_type) 270 { 271 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb); 272 273 memset(hdr, 0, sizeof(struct qeth_hdr)); 274 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; 275 276 /* set byte byte 3 to casting flags */ 277 if (cast_type == RTN_MULTICAST) 278 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST; 279 else if (cast_type == RTN_BROADCAST) 280 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST; 281 else 282 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST; 283 284 hdr->hdr.l2.pkt_length = skb->len - sizeof(struct qeth_hdr); 285 /* VSWITCH relies on the VLAN 286 * information to be present in 287 * the QDIO header */ 288 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) { 289 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN; 290 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI); 291 } 292 } 293 294 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card, 295 struct qeth_reply *reply, unsigned long data) 296 { 297 struct qeth_ipa_cmd *cmd; 298 299 QETH_CARD_TEXT(card, 2, "L2sdvcb"); 300 cmd = (struct qeth_ipa_cmd *) data; 301 if (cmd->hdr.return_code) { 302 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. " 303 "Continuing\n", cmd->data.setdelvlan.vlan_id, 304 QETH_CARD_IFNAME(card), cmd->hdr.return_code); 305 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command); 306 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code); 307 } 308 return 0; 309 } 310 311 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i, 312 enum qeth_ipa_cmds ipacmd) 313 { 314 struct qeth_ipa_cmd *cmd; 315 struct qeth_cmd_buffer *iob; 316 317 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd); 318 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); 319 if (!iob) 320 return -ENOMEM; 321 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); 322 cmd->data.setdelvlan.vlan_id = i; 323 return qeth_send_ipa_cmd(card, iob, 324 qeth_l2_send_setdelvlan_cb, NULL); 325 } 326 327 static void qeth_l2_process_vlans(struct qeth_card *card) 328 { 329 struct qeth_vlan_vid *id; 330 QETH_CARD_TEXT(card, 3, "L2prcvln"); 331 spin_lock_bh(&card->vlanlock); 332 list_for_each_entry(id, &card->vid_list, list) { 333 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN); 334 } 335 spin_unlock_bh(&card->vlanlock); 336 } 337 338 static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, 339 __be16 proto, u16 vid) 340 { 341 struct qeth_card *card = dev->ml_priv; 342 struct qeth_vlan_vid *id; 343 int rc; 344 345 QETH_CARD_TEXT_(card, 4, "aid:%d", vid); 346 if (!vid) 347 return 0; 348 if (card->info.type == QETH_CARD_TYPE_OSM) { 349 QETH_CARD_TEXT(card, 3, "aidOSM"); 350 return 0; 351 } 352 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { 353 QETH_CARD_TEXT(card, 3, "aidREC"); 354 return 0; 355 } 356 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC); 357 if (id) { 358 id->vid = vid; 359 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); 360 if (rc) { 361 kfree(id); 362 return rc; 363 } 364 spin_lock_bh(&card->vlanlock); 365 list_add_tail(&id->list, &card->vid_list); 366 spin_unlock_bh(&card->vlanlock); 367 } else { 368 return -ENOMEM; 369 } 370 return 0; 371 } 372 373 static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, 374 __be16 proto, u16 vid) 375 { 376 struct qeth_vlan_vid *id, *tmpid = NULL; 377 struct qeth_card *card = dev->ml_priv; 378 int rc = 0; 379 380 QETH_CARD_TEXT_(card, 4, "kid:%d", vid); 381 if (card->info.type == QETH_CARD_TYPE_OSM) { 382 QETH_CARD_TEXT(card, 3, "kidOSM"); 383 return 0; 384 } 385 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { 386 QETH_CARD_TEXT(card, 3, "kidREC"); 387 return 0; 388 } 389 spin_lock_bh(&card->vlanlock); 390 list_for_each_entry(id, &card->vid_list, list) { 391 if (id->vid == vid) { 392 list_del(&id->list); 393 tmpid = id; 394 break; 395 } 396 } 397 spin_unlock_bh(&card->vlanlock); 398 if (tmpid) { 399 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); 400 kfree(tmpid); 401 } 402 qeth_l2_set_rx_mode(card->dev); 403 return rc; 404 } 405 406 static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode) 407 { 408 QETH_DBF_TEXT(SETUP , 2, "stopcard"); 409 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); 410 411 qeth_set_allowed_threads(card, 0, 1); 412 if (card->read.state == CH_STATE_UP && 413 card->write.state == CH_STATE_UP && 414 (card->state == CARD_STATE_UP)) { 415 if (recovery_mode && 416 card->info.type != QETH_CARD_TYPE_OSN) { 417 qeth_l2_stop(card->dev); 418 } else { 419 rtnl_lock(); 420 dev_close(card->dev); 421 rtnl_unlock(); 422 } 423 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; 424 card->state = CARD_STATE_SOFTSETUP; 425 } 426 if (card->state == CARD_STATE_SOFTSETUP) { 427 qeth_l2_del_all_macs(card); 428 qeth_clear_ipacmd_list(card); 429 card->state = CARD_STATE_HARDSETUP; 430 } 431 if (card->state == CARD_STATE_HARDSETUP) { 432 qeth_qdio_clear_card(card, 0); 433 qeth_clear_qdio_buffers(card); 434 qeth_clear_working_pool_list(card); 435 card->state = CARD_STATE_DOWN; 436 } 437 if (card->state == CARD_STATE_DOWN) { 438 qeth_clear_cmd_buffers(&card->read); 439 qeth_clear_cmd_buffers(&card->write); 440 } 441 } 442 443 static int qeth_l2_process_inbound_buffer(struct qeth_card *card, 444 int budget, int *done) 445 { 446 int work_done = 0; 447 struct sk_buff *skb; 448 struct qeth_hdr *hdr; 449 unsigned int len; 450 451 *done = 0; 452 WARN_ON_ONCE(!budget); 453 while (budget) { 454 skb = qeth_core_get_next_skb(card, 455 &card->qdio.in_q->bufs[card->rx.b_index], 456 &card->rx.b_element, &card->rx.e_offset, &hdr); 457 if (!skb) { 458 *done = 1; 459 break; 460 } 461 skb->dev = card->dev; 462 switch (hdr->hdr.l2.id) { 463 case QETH_HEADER_TYPE_LAYER2: 464 skb->pkt_type = PACKET_HOST; 465 skb->protocol = eth_type_trans(skb, skb->dev); 466 if ((card->dev->features & NETIF_F_RXCSUM) 467 && ((hdr->hdr.l2.flags[1] & 468 (QETH_HDR_EXT_CSUM_HDR_REQ | 469 QETH_HDR_EXT_CSUM_TRANSP_REQ)) == 470 (QETH_HDR_EXT_CSUM_HDR_REQ | 471 QETH_HDR_EXT_CSUM_TRANSP_REQ))) 472 skb->ip_summed = CHECKSUM_UNNECESSARY; 473 else 474 skb->ip_summed = CHECKSUM_NONE; 475 if (skb->protocol == htons(ETH_P_802_2)) 476 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno; 477 len = skb->len; 478 napi_gro_receive(&card->napi, skb); 479 break; 480 case QETH_HEADER_TYPE_OSN: 481 if (card->info.type == QETH_CARD_TYPE_OSN) { 482 skb_push(skb, sizeof(struct qeth_hdr)); 483 skb_copy_to_linear_data(skb, hdr, 484 sizeof(struct qeth_hdr)); 485 len = skb->len; 486 card->osn_info.data_cb(skb); 487 break; 488 } 489 /* else unknown */ 490 default: 491 dev_kfree_skb_any(skb); 492 QETH_CARD_TEXT(card, 3, "inbunkno"); 493 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN); 494 continue; 495 } 496 work_done++; 497 budget--; 498 card->stats.rx_packets++; 499 card->stats.rx_bytes += len; 500 } 501 return work_done; 502 } 503 504 static int qeth_l2_request_initial_mac(struct qeth_card *card) 505 { 506 int rc = 0; 507 char vendor_pre[] = {0x02, 0x00, 0x00}; 508 509 QETH_DBF_TEXT(SETUP, 2, "l2reqmac"); 510 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card)); 511 512 if (MACHINE_IS_VM) { 513 rc = qeth_vm_request_mac(card); 514 if (!rc) 515 goto out; 516 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n", 517 CARD_BUS_ID(card), rc); 518 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc); 519 /* fall back to alternative mechanism: */ 520 } 521 522 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) { 523 rc = qeth_query_setadapterparms(card); 524 if (rc) { 525 QETH_DBF_MESSAGE(2, "could not query adapter " 526 "parameters on device %s: x%x\n", 527 CARD_BUS_ID(card), rc); 528 } 529 } 530 531 if (card->info.type == QETH_CARD_TYPE_IQD || 532 card->info.type == QETH_CARD_TYPE_OSM || 533 card->info.type == QETH_CARD_TYPE_OSX || 534 card->info.guestlan) { 535 rc = qeth_setadpparms_change_macaddr(card); 536 if (rc) { 537 QETH_DBF_MESSAGE(2, "couldn't get MAC address on " 538 "device %s: x%x\n", CARD_BUS_ID(card), rc); 539 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc); 540 return rc; 541 } 542 } else { 543 eth_random_addr(card->dev->dev_addr); 544 memcpy(card->dev->dev_addr, vendor_pre, 3); 545 } 546 out: 547 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len); 548 return 0; 549 } 550 551 static int qeth_l2_set_mac_address(struct net_device *dev, void *p) 552 { 553 struct sockaddr *addr = p; 554 struct qeth_card *card = dev->ml_priv; 555 int rc = 0; 556 557 QETH_CARD_TEXT(card, 3, "setmac"); 558 559 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) { 560 QETH_CARD_TEXT(card, 3, "setmcINV"); 561 return -EOPNOTSUPP; 562 } 563 564 if (card->info.type == QETH_CARD_TYPE_OSN || 565 card->info.type == QETH_CARD_TYPE_OSM || 566 card->info.type == QETH_CARD_TYPE_OSX) { 567 QETH_CARD_TEXT(card, 3, "setmcTYP"); 568 return -EOPNOTSUPP; 569 } 570 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN); 571 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { 572 QETH_CARD_TEXT(card, 3, "setmcREC"); 573 return -ERESTARTSYS; 574 } 575 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]); 576 if (!rc || (rc == -ENOENT)) 577 rc = qeth_l2_send_setmac(card, addr->sa_data); 578 return rc ? -EINVAL : 0; 579 } 580 581 static void qeth_promisc_to_bridge(struct qeth_card *card) 582 { 583 struct net_device *dev = card->dev; 584 enum qeth_ipa_promisc_modes promisc_mode; 585 int role; 586 int rc; 587 588 QETH_CARD_TEXT(card, 3, "pmisc2br"); 589 590 if (!card->options.sbp.reflect_promisc) 591 return; 592 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON 593 : SET_PROMISC_MODE_OFF; 594 if (promisc_mode == card->info.promisc_mode) 595 return; 596 597 if (promisc_mode == SET_PROMISC_MODE_ON) { 598 if (card->options.sbp.reflect_promisc_primary) 599 role = QETH_SBP_ROLE_PRIMARY; 600 else 601 role = QETH_SBP_ROLE_SECONDARY; 602 } else 603 role = QETH_SBP_ROLE_NONE; 604 605 rc = qeth_bridgeport_setrole(card, role); 606 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x", 607 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc); 608 if (!rc) { 609 card->options.sbp.role = role; 610 card->info.promisc_mode = promisc_mode; 611 } 612 613 } 614 /* New MAC address is added to the hash table and marked to be written on card 615 * only if there is not in the hash table storage already 616 * 617 */ 618 static void 619 qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha, u8 is_uc) 620 { 621 struct qeth_mac *mac; 622 623 hash_for_each_possible(card->mac_htable, mac, hnode, 624 qeth_l2_mac_hash(ha->addr)) { 625 if (is_uc == mac->is_uc && 626 !memcmp(ha->addr, mac->mac_addr, OSA_ADDR_LEN)) { 627 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING; 628 return; 629 } 630 } 631 632 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC); 633 634 if (!mac) 635 return; 636 637 memcpy(mac->mac_addr, ha->addr, OSA_ADDR_LEN); 638 mac->is_uc = is_uc; 639 mac->disp_flag = QETH_DISP_ADDR_ADD; 640 641 hash_add(card->mac_htable, &mac->hnode, 642 qeth_l2_mac_hash(mac->mac_addr)); 643 644 } 645 646 static void qeth_l2_set_rx_mode(struct net_device *dev) 647 { 648 struct qeth_card *card = dev->ml_priv; 649 struct netdev_hw_addr *ha; 650 struct qeth_mac *mac; 651 struct hlist_node *tmp; 652 int i; 653 int rc; 654 655 if (card->info.type == QETH_CARD_TYPE_OSN) 656 return; 657 658 QETH_CARD_TEXT(card, 3, "setmulti"); 659 if (qeth_threads_running(card, QETH_RECOVER_THREAD) && 660 (card->state != CARD_STATE_UP)) 661 return; 662 663 spin_lock_bh(&card->mclock); 664 665 netdev_for_each_mc_addr(ha, dev) 666 qeth_l2_add_mac(card, ha, 0); 667 668 netdev_for_each_uc_addr(ha, dev) 669 qeth_l2_add_mac(card, ha, 1); 670 671 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { 672 if (mac->disp_flag == QETH_DISP_ADDR_DELETE) { 673 qeth_l2_remove_mac(card, mac); 674 hash_del(&mac->hnode); 675 kfree(mac); 676 677 } else if (mac->disp_flag == QETH_DISP_ADDR_ADD) { 678 rc = qeth_l2_write_mac(card, mac); 679 if (rc) { 680 hash_del(&mac->hnode); 681 kfree(mac); 682 } else 683 mac->disp_flag = QETH_DISP_ADDR_DELETE; 684 } else 685 mac->disp_flag = QETH_DISP_ADDR_DELETE; 686 } 687 688 spin_unlock_bh(&card->mclock); 689 690 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) 691 qeth_setadp_promisc_mode(card); 692 else 693 qeth_promisc_to_bridge(card); 694 } 695 696 static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb, 697 struct net_device *dev) 698 { 699 int rc; 700 struct qeth_hdr *hdr = NULL; 701 int elements = 0; 702 struct qeth_card *card = dev->ml_priv; 703 struct sk_buff *new_skb = skb; 704 int cast_type = qeth_l2_get_cast_type(card, skb); 705 struct qeth_qdio_out_q *queue; 706 int tx_bytes = skb->len; 707 int data_offset = -1; 708 int elements_needed = 0; 709 int hd_len = 0; 710 int nr_frags; 711 712 if (card->qdio.do_prio_queueing || (cast_type && 713 card->info.is_multicast_different)) 714 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb, 715 qeth_get_ip_version(skb), cast_type)]; 716 else 717 queue = card->qdio.out_qs[card->qdio.default_out_queue]; 718 719 if ((card->state != CARD_STATE_UP) || !card->lan_online) { 720 card->stats.tx_carrier_errors++; 721 goto tx_drop; 722 } 723 724 if ((card->info.type == QETH_CARD_TYPE_OSN) && 725 (skb->protocol == htons(ETH_P_IPV6))) 726 goto tx_drop; 727 728 if (card->options.performance_stats) { 729 card->perf_stats.outbound_cnt++; 730 card->perf_stats.outbound_start_time = qeth_get_micros(); 731 } 732 netif_stop_queue(dev); 733 734 /* fix hardware limitation: as long as we do not have sbal 735 * chaining we can not send long frag lists 736 */ 737 if ((card->info.type != QETH_CARD_TYPE_IQD) && 738 !qeth_get_elements_no(card, new_skb, 0, 0)) { 739 int lin_rc = skb_linearize(new_skb); 740 741 if (card->options.performance_stats) { 742 if (lin_rc) 743 card->perf_stats.tx_linfail++; 744 else 745 card->perf_stats.tx_lin++; 746 } 747 if (lin_rc) 748 goto tx_drop; 749 } 750 751 if (card->info.type == QETH_CARD_TYPE_OSN) 752 hdr = (struct qeth_hdr *)skb->data; 753 else { 754 if (card->info.type == QETH_CARD_TYPE_IQD) { 755 new_skb = skb; 756 data_offset = ETH_HLEN; 757 hd_len = ETH_HLEN; 758 hdr = kmem_cache_alloc(qeth_core_header_cache, 759 GFP_ATOMIC); 760 if (!hdr) 761 goto tx_drop; 762 elements_needed++; 763 skb_reset_mac_header(new_skb); 764 qeth_l2_fill_header(card, hdr, new_skb, cast_type); 765 hdr->hdr.l2.pkt_length = new_skb->len; 766 memcpy(((char *)hdr) + sizeof(struct qeth_hdr), 767 skb_mac_header(new_skb), ETH_HLEN); 768 } else { 769 /* create a clone with writeable headroom */ 770 new_skb = skb_realloc_headroom(skb, 771 sizeof(struct qeth_hdr)); 772 if (!new_skb) 773 goto tx_drop; 774 hdr = skb_push(new_skb, sizeof(struct qeth_hdr)); 775 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr)); 776 qeth_l2_fill_header(card, hdr, new_skb, cast_type); 777 if (new_skb->ip_summed == CHECKSUM_PARTIAL) 778 qeth_l2_hdr_csum(card, hdr, new_skb); 779 } 780 } 781 782 elements = qeth_get_elements_no(card, new_skb, elements_needed, 783 (data_offset > 0) ? data_offset : 0); 784 if (!elements) { 785 if (data_offset >= 0) 786 kmem_cache_free(qeth_core_header_cache, hdr); 787 goto tx_drop; 788 } 789 790 if (card->info.type != QETH_CARD_TYPE_IQD) { 791 if (qeth_hdr_chk_and_bounce(new_skb, &hdr, 792 sizeof(struct qeth_hdr_layer2))) 793 goto tx_drop; 794 rc = qeth_do_send_packet(card, queue, new_skb, hdr, 795 elements); 796 } else 797 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr, 798 data_offset, hd_len); 799 if (!rc) { 800 card->stats.tx_packets++; 801 card->stats.tx_bytes += tx_bytes; 802 if (card->options.performance_stats) { 803 nr_frags = skb_shinfo(new_skb)->nr_frags; 804 if (nr_frags) { 805 card->perf_stats.sg_skbs_sent++; 806 /* nr_frags + skb->data */ 807 card->perf_stats.sg_frags_sent += nr_frags + 1; 808 } 809 } 810 if (new_skb != skb) 811 dev_kfree_skb_any(skb); 812 rc = NETDEV_TX_OK; 813 } else { 814 if (data_offset >= 0) 815 kmem_cache_free(qeth_core_header_cache, hdr); 816 817 if (rc == -EBUSY) { 818 if (new_skb != skb) 819 dev_kfree_skb_any(new_skb); 820 return NETDEV_TX_BUSY; 821 } else 822 goto tx_drop; 823 } 824 825 netif_wake_queue(dev); 826 if (card->options.performance_stats) 827 card->perf_stats.outbound_time += qeth_get_micros() - 828 card->perf_stats.outbound_start_time; 829 return rc; 830 831 tx_drop: 832 card->stats.tx_dropped++; 833 card->stats.tx_errors++; 834 if ((new_skb != skb) && new_skb) 835 dev_kfree_skb_any(new_skb); 836 dev_kfree_skb_any(skb); 837 netif_wake_queue(dev); 838 return NETDEV_TX_OK; 839 } 840 841 static int __qeth_l2_open(struct net_device *dev) 842 { 843 struct qeth_card *card = dev->ml_priv; 844 int rc = 0; 845 846 QETH_CARD_TEXT(card, 4, "qethopen"); 847 if (card->state == CARD_STATE_UP) 848 return rc; 849 if (card->state != CARD_STATE_SOFTSETUP) 850 return -ENODEV; 851 852 if ((card->info.type != QETH_CARD_TYPE_OSN) && 853 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) { 854 QETH_CARD_TEXT(card, 4, "nomacadr"); 855 return -EPERM; 856 } 857 card->data.state = CH_STATE_UP; 858 card->state = CARD_STATE_UP; 859 netif_start_queue(dev); 860 861 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) { 862 napi_enable(&card->napi); 863 napi_schedule(&card->napi); 864 } else 865 rc = -EIO; 866 return rc; 867 } 868 869 static int qeth_l2_open(struct net_device *dev) 870 { 871 struct qeth_card *card = dev->ml_priv; 872 873 QETH_CARD_TEXT(card, 5, "qethope_"); 874 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { 875 QETH_CARD_TEXT(card, 3, "openREC"); 876 return -ERESTARTSYS; 877 } 878 return __qeth_l2_open(dev); 879 } 880 881 static int qeth_l2_stop(struct net_device *dev) 882 { 883 struct qeth_card *card = dev->ml_priv; 884 885 QETH_CARD_TEXT(card, 4, "qethstop"); 886 netif_tx_disable(dev); 887 if (card->state == CARD_STATE_UP) { 888 card->state = CARD_STATE_SOFTSETUP; 889 napi_disable(&card->napi); 890 } 891 return 0; 892 } 893 894 static const struct device_type qeth_l2_devtype = { 895 .name = "qeth_layer2", 896 .groups = qeth_l2_attr_groups, 897 }; 898 899 static int qeth_l2_probe_device(struct ccwgroup_device *gdev) 900 { 901 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 902 int rc; 903 904 if (gdev->dev.type == &qeth_generic_devtype) { 905 rc = qeth_l2_create_device_attributes(&gdev->dev); 906 if (rc) 907 return rc; 908 } 909 INIT_LIST_HEAD(&card->vid_list); 910 hash_init(card->mac_htable); 911 card->options.layer2 = 1; 912 card->info.hwtrap = 0; 913 return 0; 914 } 915 916 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev) 917 { 918 struct qeth_card *card = dev_get_drvdata(&cgdev->dev); 919 920 if (cgdev->dev.type == &qeth_generic_devtype) 921 qeth_l2_remove_device_attributes(&cgdev->dev); 922 qeth_set_allowed_threads(card, 0, 1); 923 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); 924 925 if (cgdev->state == CCWGROUP_ONLINE) 926 qeth_l2_set_offline(cgdev); 927 928 if (card->dev) { 929 netif_napi_del(&card->napi); 930 unregister_netdev(card->dev); 931 card->dev = NULL; 932 } 933 return; 934 } 935 936 static const struct ethtool_ops qeth_l2_ethtool_ops = { 937 .get_link = ethtool_op_get_link, 938 .get_strings = qeth_core_get_strings, 939 .get_ethtool_stats = qeth_core_get_ethtool_stats, 940 .get_sset_count = qeth_core_get_sset_count, 941 .get_drvinfo = qeth_core_get_drvinfo, 942 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings, 943 }; 944 945 static const struct ethtool_ops qeth_l2_osn_ops = { 946 .get_strings = qeth_core_get_strings, 947 .get_ethtool_stats = qeth_core_get_ethtool_stats, 948 .get_sset_count = qeth_core_get_sset_count, 949 .get_drvinfo = qeth_core_get_drvinfo, 950 }; 951 952 static const struct net_device_ops qeth_l2_netdev_ops = { 953 .ndo_open = qeth_l2_open, 954 .ndo_stop = qeth_l2_stop, 955 .ndo_get_stats = qeth_get_stats, 956 .ndo_start_xmit = qeth_l2_hard_start_xmit, 957 .ndo_validate_addr = eth_validate_addr, 958 .ndo_set_rx_mode = qeth_l2_set_rx_mode, 959 .ndo_do_ioctl = qeth_do_ioctl, 960 .ndo_set_mac_address = qeth_l2_set_mac_address, 961 .ndo_change_mtu = qeth_change_mtu, 962 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid, 963 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid, 964 .ndo_tx_timeout = qeth_tx_timeout, 965 .ndo_fix_features = qeth_fix_features, 966 .ndo_set_features = qeth_set_features 967 }; 968 969 static int qeth_l2_setup_netdev(struct qeth_card *card) 970 { 971 switch (card->info.type) { 972 case QETH_CARD_TYPE_IQD: 973 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN, 974 ether_setup); 975 break; 976 case QETH_CARD_TYPE_OSN: 977 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN, 978 ether_setup); 979 break; 980 default: 981 card->dev = alloc_etherdev(0); 982 } 983 984 if (!card->dev) 985 return -ENODEV; 986 987 card->dev->ml_priv = card; 988 card->dev->watchdog_timeo = QETH_TX_TIMEOUT; 989 card->dev->mtu = card->info.initial_mtu; 990 card->dev->min_mtu = 64; 991 card->dev->max_mtu = ETH_MAX_MTU; 992 card->dev->netdev_ops = &qeth_l2_netdev_ops; 993 if (card->info.type == QETH_CARD_TYPE_OSN) { 994 card->dev->ethtool_ops = &qeth_l2_osn_ops; 995 card->dev->flags |= IFF_NOARP; 996 } else { 997 card->dev->ethtool_ops = &qeth_l2_ethtool_ops; 998 } 999 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; 1000 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) { 1001 card->dev->hw_features = NETIF_F_SG; 1002 card->dev->vlan_features = NETIF_F_SG; 1003 /* OSA 3S and earlier has no RX/TX support */ 1004 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) { 1005 card->dev->hw_features |= NETIF_F_IP_CSUM; 1006 card->dev->vlan_features |= NETIF_F_IP_CSUM; 1007 } 1008 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) { 1009 card->dev->hw_features |= NETIF_F_RXCSUM; 1010 card->dev->vlan_features |= NETIF_F_RXCSUM; 1011 } 1012 } 1013 card->info.broadcast_capable = 1; 1014 qeth_l2_request_initial_mac(card); 1015 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) * 1016 PAGE_SIZE; 1017 SET_NETDEV_DEV(card->dev, &card->gdev->dev); 1018 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); 1019 netif_carrier_off(card->dev); 1020 return register_netdev(card->dev); 1021 } 1022 1023 static int qeth_l2_start_ipassists(struct qeth_card *card) 1024 { 1025 /* configure isolation level */ 1026 if (qeth_set_access_ctrl_online(card, 0)) 1027 return -ENODEV; 1028 return 0; 1029 } 1030 1031 static void qeth_l2_trace_features(struct qeth_card *card) 1032 { 1033 QETH_CARD_TEXT(card, 2, "l2featur"); 1034 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs, 1035 sizeof(card->options.sbp.supported_funcs)); 1036 } 1037 1038 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode) 1039 { 1040 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 1041 int rc = 0; 1042 enum qeth_card_states recover_flag; 1043 1044 mutex_lock(&card->discipline_mutex); 1045 mutex_lock(&card->conf_mutex); 1046 QETH_DBF_TEXT(SETUP, 2, "setonlin"); 1047 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); 1048 1049 recover_flag = card->state; 1050 rc = qeth_core_hardsetup_card(card); 1051 if (rc) { 1052 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc); 1053 rc = -ENODEV; 1054 goto out_remove; 1055 } 1056 qeth_bridgeport_query_support(card); 1057 if (card->options.sbp.supported_funcs) 1058 dev_info(&card->gdev->dev, 1059 "The device represents a Bridge Capable Port\n"); 1060 qeth_trace_features(card); 1061 qeth_l2_trace_features(card); 1062 1063 if (!card->dev && qeth_l2_setup_netdev(card)) { 1064 rc = -ENODEV; 1065 goto out_remove; 1066 } 1067 1068 if (card->info.type != QETH_CARD_TYPE_OSN) 1069 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]); 1070 1071 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) { 1072 if (card->info.hwtrap && 1073 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)) 1074 card->info.hwtrap = 0; 1075 } else 1076 card->info.hwtrap = 0; 1077 1078 qeth_l2_setup_bridgeport_attrs(card); 1079 1080 card->state = CARD_STATE_HARDSETUP; 1081 memset(&card->rx, 0, sizeof(struct qeth_rx)); 1082 qeth_print_status_message(card); 1083 1084 /* softsetup */ 1085 QETH_DBF_TEXT(SETUP, 2, "softsetp"); 1086 1087 if ((card->info.type == QETH_CARD_TYPE_OSD) || 1088 (card->info.type == QETH_CARD_TYPE_OSX)) { 1089 rc = qeth_l2_start_ipassists(card); 1090 if (rc) 1091 goto out_remove; 1092 } 1093 1094 if (card->info.type != QETH_CARD_TYPE_OSN && 1095 card->info.type != QETH_CARD_TYPE_OSM) 1096 qeth_l2_process_vlans(card); 1097 1098 netif_tx_disable(card->dev); 1099 1100 rc = qeth_init_qdio_queues(card); 1101 if (rc) { 1102 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc); 1103 rc = -ENODEV; 1104 goto out_remove; 1105 } 1106 card->state = CARD_STATE_SOFTSETUP; 1107 if (card->lan_online) 1108 netif_carrier_on(card->dev); 1109 else 1110 netif_carrier_off(card->dev); 1111 1112 qeth_set_allowed_threads(card, 0xffffffff, 0); 1113 if (recover_flag == CARD_STATE_RECOVER) { 1114 if (recovery_mode && 1115 card->info.type != QETH_CARD_TYPE_OSN) { 1116 __qeth_l2_open(card->dev); 1117 } else { 1118 rtnl_lock(); 1119 dev_open(card->dev); 1120 rtnl_unlock(); 1121 } 1122 /* this also sets saved unicast addresses */ 1123 qeth_l2_set_rx_mode(card->dev); 1124 rtnl_lock(); 1125 qeth_recover_features(card->dev); 1126 rtnl_unlock(); 1127 } 1128 /* let user_space know that device is online */ 1129 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); 1130 mutex_unlock(&card->conf_mutex); 1131 mutex_unlock(&card->discipline_mutex); 1132 return 0; 1133 1134 out_remove: 1135 qeth_l2_stop_card(card, 0); 1136 ccw_device_set_offline(CARD_DDEV(card)); 1137 ccw_device_set_offline(CARD_WDEV(card)); 1138 ccw_device_set_offline(CARD_RDEV(card)); 1139 qdio_free(CARD_DDEV(card)); 1140 if (recover_flag == CARD_STATE_RECOVER) 1141 card->state = CARD_STATE_RECOVER; 1142 else 1143 card->state = CARD_STATE_DOWN; 1144 mutex_unlock(&card->conf_mutex); 1145 mutex_unlock(&card->discipline_mutex); 1146 return rc; 1147 } 1148 1149 static int qeth_l2_set_online(struct ccwgroup_device *gdev) 1150 { 1151 return __qeth_l2_set_online(gdev, 0); 1152 } 1153 1154 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev, 1155 int recovery_mode) 1156 { 1157 struct qeth_card *card = dev_get_drvdata(&cgdev->dev); 1158 int rc = 0, rc2 = 0, rc3 = 0; 1159 enum qeth_card_states recover_flag; 1160 1161 mutex_lock(&card->discipline_mutex); 1162 mutex_lock(&card->conf_mutex); 1163 QETH_DBF_TEXT(SETUP, 3, "setoffl"); 1164 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *)); 1165 1166 if (card->dev && netif_carrier_ok(card->dev)) 1167 netif_carrier_off(card->dev); 1168 recover_flag = card->state; 1169 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) { 1170 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 1171 card->info.hwtrap = 1; 1172 } 1173 qeth_l2_stop_card(card, recovery_mode); 1174 rc = ccw_device_set_offline(CARD_DDEV(card)); 1175 rc2 = ccw_device_set_offline(CARD_WDEV(card)); 1176 rc3 = ccw_device_set_offline(CARD_RDEV(card)); 1177 if (!rc) 1178 rc = (rc2) ? rc2 : rc3; 1179 if (rc) 1180 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); 1181 qdio_free(CARD_DDEV(card)); 1182 if (recover_flag == CARD_STATE_UP) 1183 card->state = CARD_STATE_RECOVER; 1184 /* let user_space know that device is offline */ 1185 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE); 1186 mutex_unlock(&card->conf_mutex); 1187 mutex_unlock(&card->discipline_mutex); 1188 return 0; 1189 } 1190 1191 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev) 1192 { 1193 return __qeth_l2_set_offline(cgdev, 0); 1194 } 1195 1196 static int qeth_l2_recover(void *ptr) 1197 { 1198 struct qeth_card *card; 1199 int rc = 0; 1200 1201 card = (struct qeth_card *) ptr; 1202 QETH_CARD_TEXT(card, 2, "recover1"); 1203 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) 1204 return 0; 1205 QETH_CARD_TEXT(card, 2, "recover2"); 1206 dev_warn(&card->gdev->dev, 1207 "A recovery process has been started for the device\n"); 1208 qeth_set_recovery_task(card); 1209 __qeth_l2_set_offline(card->gdev, 1); 1210 rc = __qeth_l2_set_online(card->gdev, 1); 1211 if (!rc) 1212 dev_info(&card->gdev->dev, 1213 "Device successfully recovered!\n"); 1214 else { 1215 qeth_close_dev(card); 1216 dev_warn(&card->gdev->dev, "The qeth device driver " 1217 "failed to recover an error on the device\n"); 1218 } 1219 qeth_clear_recovery_task(card); 1220 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); 1221 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); 1222 return 0; 1223 } 1224 1225 static int __init qeth_l2_init(void) 1226 { 1227 pr_info("register layer 2 discipline\n"); 1228 return 0; 1229 } 1230 1231 static void __exit qeth_l2_exit(void) 1232 { 1233 pr_info("unregister layer 2 discipline\n"); 1234 } 1235 1236 static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev) 1237 { 1238 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 1239 1240 if (card->dev) 1241 netif_device_detach(card->dev); 1242 qeth_set_allowed_threads(card, 0, 1); 1243 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); 1244 if (gdev->state == CCWGROUP_OFFLINE) 1245 return 0; 1246 if (card->state == CARD_STATE_UP) { 1247 if (card->info.hwtrap) 1248 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 1249 __qeth_l2_set_offline(card->gdev, 1); 1250 } else 1251 __qeth_l2_set_offline(card->gdev, 0); 1252 return 0; 1253 } 1254 1255 static int qeth_l2_pm_resume(struct ccwgroup_device *gdev) 1256 { 1257 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 1258 int rc = 0; 1259 1260 if (gdev->state == CCWGROUP_OFFLINE) 1261 goto out; 1262 1263 if (card->state == CARD_STATE_RECOVER) { 1264 rc = __qeth_l2_set_online(card->gdev, 1); 1265 if (rc) { 1266 rtnl_lock(); 1267 dev_close(card->dev); 1268 rtnl_unlock(); 1269 } 1270 } else 1271 rc = __qeth_l2_set_online(card->gdev, 0); 1272 out: 1273 qeth_set_allowed_threads(card, 0xffffffff, 0); 1274 if (card->dev) 1275 netif_device_attach(card->dev); 1276 if (rc) 1277 dev_warn(&card->gdev->dev, "The qeth device driver " 1278 "failed to recover an error on the device\n"); 1279 return rc; 1280 } 1281 1282 /* Returns zero if the command is successfully "consumed" */ 1283 static int qeth_l2_control_event(struct qeth_card *card, 1284 struct qeth_ipa_cmd *cmd) 1285 { 1286 switch (cmd->hdr.command) { 1287 case IPA_CMD_SETBRIDGEPORT_OSA: 1288 case IPA_CMD_SETBRIDGEPORT_IQD: 1289 if (cmd->data.sbp.hdr.command_code == 1290 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) { 1291 qeth_bridge_state_change(card, cmd); 1292 return 0; 1293 } else 1294 return 1; 1295 case IPA_CMD_ADDRESS_CHANGE_NOTIF: 1296 qeth_bridge_host_event(card, cmd); 1297 return 0; 1298 default: 1299 return 1; 1300 } 1301 } 1302 1303 struct qeth_discipline qeth_l2_discipline = { 1304 .devtype = &qeth_l2_devtype, 1305 .start_poll = qeth_qdio_start_poll, 1306 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler, 1307 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler, 1308 .process_rx_buffer = qeth_l2_process_inbound_buffer, 1309 .recover = qeth_l2_recover, 1310 .setup = qeth_l2_probe_device, 1311 .remove = qeth_l2_remove_device, 1312 .set_online = qeth_l2_set_online, 1313 .set_offline = qeth_l2_set_offline, 1314 .freeze = qeth_l2_pm_suspend, 1315 .thaw = qeth_l2_pm_resume, 1316 .restore = qeth_l2_pm_resume, 1317 .do_ioctl = NULL, 1318 .control_event_handler = qeth_l2_control_event, 1319 }; 1320 EXPORT_SYMBOL_GPL(qeth_l2_discipline); 1321 1322 static int qeth_osn_send_control_data(struct qeth_card *card, int len, 1323 struct qeth_cmd_buffer *iob) 1324 { 1325 unsigned long flags; 1326 int rc = 0; 1327 1328 QETH_CARD_TEXT(card, 5, "osndctrd"); 1329 1330 wait_event(card->wait_q, 1331 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); 1332 qeth_prepare_control_data(card, len, iob); 1333 QETH_CARD_TEXT(card, 6, "osnoirqp"); 1334 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); 1335 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, 1336 (addr_t) iob, 0, 0); 1337 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); 1338 if (rc) { 1339 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: " 1340 "ccw_device_start rc = %i\n", rc); 1341 QETH_CARD_TEXT_(card, 2, " err%d", rc); 1342 qeth_release_buffer(iob->channel, iob); 1343 atomic_set(&card->write.irq_pending, 0); 1344 wake_up(&card->wait_q); 1345 } 1346 return rc; 1347 } 1348 1349 static int qeth_osn_send_ipa_cmd(struct qeth_card *card, 1350 struct qeth_cmd_buffer *iob, int data_len) 1351 { 1352 u16 s1, s2; 1353 1354 QETH_CARD_TEXT(card, 4, "osndipa"); 1355 1356 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2); 1357 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len); 1358 s2 = (u16)data_len; 1359 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); 1360 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); 1361 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); 1362 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); 1363 return qeth_osn_send_control_data(card, s1, iob); 1364 } 1365 1366 int qeth_osn_assist(struct net_device *dev, void *data, int data_len) 1367 { 1368 struct qeth_cmd_buffer *iob; 1369 struct qeth_card *card; 1370 int rc; 1371 1372 if (!dev) 1373 return -ENODEV; 1374 card = dev->ml_priv; 1375 if (!card) 1376 return -ENODEV; 1377 QETH_CARD_TEXT(card, 2, "osnsdmc"); 1378 if (!qeth_card_hw_is_reachable(card)) 1379 return -ENODEV; 1380 iob = qeth_wait_for_buffer(&card->write); 1381 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len); 1382 rc = qeth_osn_send_ipa_cmd(card, iob, data_len); 1383 return rc; 1384 } 1385 EXPORT_SYMBOL(qeth_osn_assist); 1386 1387 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev, 1388 int (*assist_cb)(struct net_device *, void *), 1389 int (*data_cb)(struct sk_buff *)) 1390 { 1391 struct qeth_card *card; 1392 1393 *dev = qeth_l2_netdev_by_devno(read_dev_no); 1394 if (*dev == NULL) 1395 return -ENODEV; 1396 card = (*dev)->ml_priv; 1397 if (!card) 1398 return -ENODEV; 1399 QETH_CARD_TEXT(card, 2, "osnreg"); 1400 if ((assist_cb == NULL) || (data_cb == NULL)) 1401 return -EINVAL; 1402 card->osn_info.assist_cb = assist_cb; 1403 card->osn_info.data_cb = data_cb; 1404 return 0; 1405 } 1406 EXPORT_SYMBOL(qeth_osn_register); 1407 1408 void qeth_osn_deregister(struct net_device *dev) 1409 { 1410 struct qeth_card *card; 1411 1412 if (!dev) 1413 return; 1414 card = dev->ml_priv; 1415 if (!card) 1416 return; 1417 QETH_CARD_TEXT(card, 2, "osndereg"); 1418 card->osn_info.assist_cb = NULL; 1419 card->osn_info.data_cb = NULL; 1420 return; 1421 } 1422 EXPORT_SYMBOL(qeth_osn_deregister); 1423 1424 /* SETBRIDGEPORT support, async notifications */ 1425 1426 enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset}; 1427 1428 /** 1429 * qeth_bridge_emit_host_event() - bridgeport address change notification 1430 * @card: qeth_card structure pointer, for udev events. 1431 * @evtype: "normal" register/unregister, or abort, or reset. For abort 1432 * and reset token and addr_lnid are unused and may be NULL. 1433 * @code: event bitmask: high order bit 0x80 value 1 means removal of an 1434 * object, 0 - addition of an object. 1435 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC. 1436 * @token: "network token" structure identifying physical address of the port. 1437 * @addr_lnid: pointer to structure with MAC address and VLAN ID. 1438 * 1439 * This function is called when registrations and deregistrations are 1440 * reported by the hardware, and also when notifications are enabled - 1441 * for all currently registered addresses. 1442 */ 1443 static void qeth_bridge_emit_host_event(struct qeth_card *card, 1444 enum qeth_an_event_type evtype, 1445 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid) 1446 { 1447 char str[7][32]; 1448 char *env[8]; 1449 int i = 0; 1450 1451 switch (evtype) { 1452 case anev_reg_unreg: 1453 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s", 1454 (code & IPA_ADDR_CHANGE_CODE_REMOVAL) 1455 ? "deregister" : "register"); 1456 env[i] = str[i]; i++; 1457 if (code & IPA_ADDR_CHANGE_CODE_VLANID) { 1458 snprintf(str[i], sizeof(str[i]), "VLAN=%d", 1459 addr_lnid->lnid); 1460 env[i] = str[i]; i++; 1461 } 1462 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) { 1463 snprintf(str[i], sizeof(str[i]), "MAC=%pM", 1464 addr_lnid->mac); 1465 env[i] = str[i]; i++; 1466 } 1467 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x", 1468 token->cssid, token->ssid, token->devnum); 1469 env[i] = str[i]; i++; 1470 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid); 1471 env[i] = str[i]; i++; 1472 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x", 1473 token->chpid); 1474 env[i] = str[i]; i++; 1475 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid); 1476 env[i] = str[i]; i++; 1477 break; 1478 case anev_abort: 1479 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort"); 1480 env[i] = str[i]; i++; 1481 break; 1482 case anev_reset: 1483 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset"); 1484 env[i] = str[i]; i++; 1485 break; 1486 } 1487 env[i] = NULL; 1488 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env); 1489 } 1490 1491 struct qeth_bridge_state_data { 1492 struct work_struct worker; 1493 struct qeth_card *card; 1494 struct qeth_sbp_state_change qports; 1495 }; 1496 1497 static void qeth_bridge_state_change_worker(struct work_struct *work) 1498 { 1499 struct qeth_bridge_state_data *data = 1500 container_of(work, struct qeth_bridge_state_data, worker); 1501 /* We are only interested in the first entry - local port */ 1502 struct qeth_sbp_port_entry *entry = &data->qports.entry[0]; 1503 char env_locrem[32]; 1504 char env_role[32]; 1505 char env_state[32]; 1506 char *env[] = { 1507 env_locrem, 1508 env_role, 1509 env_state, 1510 NULL 1511 }; 1512 1513 /* Role should not change by itself, but if it did, */ 1514 /* information from the hardware is authoritative. */ 1515 mutex_lock(&data->card->conf_mutex); 1516 data->card->options.sbp.role = entry->role; 1517 mutex_unlock(&data->card->conf_mutex); 1518 1519 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange"); 1520 snprintf(env_role, sizeof(env_role), "ROLE=%s", 1521 (entry->role == QETH_SBP_ROLE_NONE) ? "none" : 1522 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" : 1523 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" : 1524 "<INVALID>"); 1525 snprintf(env_state, sizeof(env_state), "STATE=%s", 1526 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" : 1527 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" : 1528 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" : 1529 "<INVALID>"); 1530 kobject_uevent_env(&data->card->gdev->dev.kobj, 1531 KOBJ_CHANGE, env); 1532 kfree(data); 1533 } 1534 1535 static void qeth_bridge_state_change(struct qeth_card *card, 1536 struct qeth_ipa_cmd *cmd) 1537 { 1538 struct qeth_sbp_state_change *qports = 1539 &cmd->data.sbp.data.state_change; 1540 struct qeth_bridge_state_data *data; 1541 int extrasize; 1542 1543 QETH_CARD_TEXT(card, 2, "brstchng"); 1544 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { 1545 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length); 1546 return; 1547 } 1548 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries; 1549 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize, 1550 GFP_ATOMIC); 1551 if (!data) { 1552 QETH_CARD_TEXT(card, 2, "BPSalloc"); 1553 return; 1554 } 1555 INIT_WORK(&data->worker, qeth_bridge_state_change_worker); 1556 data->card = card; 1557 memcpy(&data->qports, qports, 1558 sizeof(struct qeth_sbp_state_change) + extrasize); 1559 queue_work(qeth_wq, &data->worker); 1560 } 1561 1562 struct qeth_bridge_host_data { 1563 struct work_struct worker; 1564 struct qeth_card *card; 1565 struct qeth_ipacmd_addr_change hostevs; 1566 }; 1567 1568 static void qeth_bridge_host_event_worker(struct work_struct *work) 1569 { 1570 struct qeth_bridge_host_data *data = 1571 container_of(work, struct qeth_bridge_host_data, worker); 1572 int i; 1573 1574 if (data->hostevs.lost_event_mask) { 1575 dev_info(&data->card->gdev->dev, 1576 "Address notification from the Bridge Port stopped %s (%s)\n", 1577 data->card->dev->name, 1578 (data->hostevs.lost_event_mask == 0x01) 1579 ? "Overflow" 1580 : (data->hostevs.lost_event_mask == 0x02) 1581 ? "Bridge port state change" 1582 : "Unknown reason"); 1583 mutex_lock(&data->card->conf_mutex); 1584 data->card->options.sbp.hostnotification = 0; 1585 mutex_unlock(&data->card->conf_mutex); 1586 qeth_bridge_emit_host_event(data->card, anev_abort, 1587 0, NULL, NULL); 1588 } else 1589 for (i = 0; i < data->hostevs.num_entries; i++) { 1590 struct qeth_ipacmd_addr_change_entry *entry = 1591 &data->hostevs.entry[i]; 1592 qeth_bridge_emit_host_event(data->card, 1593 anev_reg_unreg, 1594 entry->change_code, 1595 &entry->token, &entry->addr_lnid); 1596 } 1597 kfree(data); 1598 } 1599 1600 static void qeth_bridge_host_event(struct qeth_card *card, 1601 struct qeth_ipa_cmd *cmd) 1602 { 1603 struct qeth_ipacmd_addr_change *hostevs = 1604 &cmd->data.addrchange; 1605 struct qeth_bridge_host_data *data; 1606 int extrasize; 1607 1608 QETH_CARD_TEXT(card, 2, "brhostev"); 1609 if (cmd->hdr.return_code != 0x0000) { 1610 if (cmd->hdr.return_code == 0x0010) { 1611 if (hostevs->lost_event_mask == 0x00) 1612 hostevs->lost_event_mask = 0xff; 1613 } else { 1614 QETH_CARD_TEXT_(card, 2, "BPHe%04x", 1615 cmd->hdr.return_code); 1616 return; 1617 } 1618 } 1619 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) * 1620 hostevs->num_entries; 1621 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize, 1622 GFP_ATOMIC); 1623 if (!data) { 1624 QETH_CARD_TEXT(card, 2, "BPHalloc"); 1625 return; 1626 } 1627 INIT_WORK(&data->worker, qeth_bridge_host_event_worker); 1628 data->card = card; 1629 memcpy(&data->hostevs, hostevs, 1630 sizeof(struct qeth_ipacmd_addr_change) + extrasize); 1631 queue_work(qeth_wq, &data->worker); 1632 } 1633 1634 /* SETBRIDGEPORT support; sending commands */ 1635 1636 struct _qeth_sbp_cbctl { 1637 u16 ipa_rc; 1638 u16 cmd_rc; 1639 union { 1640 u32 supported; 1641 struct { 1642 enum qeth_sbp_roles *role; 1643 enum qeth_sbp_states *state; 1644 } qports; 1645 } data; 1646 }; 1647 1648 /** 1649 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes. 1650 * @card: qeth_card structure pointer, for debug messages. 1651 * @cbctl: state structure with hardware return codes. 1652 * @setcmd: IPA command code 1653 * 1654 * Returns negative errno-compatible error indication or 0 on success. 1655 */ 1656 static int qeth_bridgeport_makerc(struct qeth_card *card, 1657 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd) 1658 { 1659 int rc; 1660 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD); 1661 1662 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) || 1663 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc))) 1664 switch (cbctl->cmd_rc) { 1665 case IPA_RC_SUCCESS: 1666 rc = 0; 1667 break; 1668 case IPA_RC_L2_UNSUPPORTED_CMD: 1669 case IPA_RC_UNSUPPORTED_COMMAND: 1670 rc = -EOPNOTSUPP; 1671 break; 1672 case IPA_RC_SBP_OSA_NOT_CONFIGURED: 1673 case IPA_RC_SBP_IQD_NOT_CONFIGURED: 1674 rc = -ENODEV; /* maybe not the best code here? */ 1675 dev_err(&card->gdev->dev, 1676 "The device is not configured as a Bridge Port\n"); 1677 break; 1678 case IPA_RC_SBP_OSA_OS_MISMATCH: 1679 case IPA_RC_SBP_IQD_OS_MISMATCH: 1680 rc = -EPERM; 1681 dev_err(&card->gdev->dev, 1682 "A Bridge Port is already configured by a different operating system\n"); 1683 break; 1684 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY: 1685 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY: 1686 switch (setcmd) { 1687 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT: 1688 rc = -EEXIST; 1689 dev_err(&card->gdev->dev, 1690 "The LAN already has a primary Bridge Port\n"); 1691 break; 1692 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT: 1693 rc = -EBUSY; 1694 dev_err(&card->gdev->dev, 1695 "The device is already a primary Bridge Port\n"); 1696 break; 1697 default: 1698 rc = -EIO; 1699 } 1700 break; 1701 case IPA_RC_SBP_OSA_CURRENT_SECOND: 1702 case IPA_RC_SBP_IQD_CURRENT_SECOND: 1703 rc = -EBUSY; 1704 dev_err(&card->gdev->dev, 1705 "The device is already a secondary Bridge Port\n"); 1706 break; 1707 case IPA_RC_SBP_OSA_LIMIT_SECOND: 1708 case IPA_RC_SBP_IQD_LIMIT_SECOND: 1709 rc = -EEXIST; 1710 dev_err(&card->gdev->dev, 1711 "The LAN cannot have more secondary Bridge Ports\n"); 1712 break; 1713 case IPA_RC_SBP_OSA_CURRENT_PRIMARY: 1714 case IPA_RC_SBP_IQD_CURRENT_PRIMARY: 1715 rc = -EBUSY; 1716 dev_err(&card->gdev->dev, 1717 "The device is already a primary Bridge Port\n"); 1718 break; 1719 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN: 1720 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN: 1721 rc = -EACCES; 1722 dev_err(&card->gdev->dev, 1723 "The device is not authorized to be a Bridge Port\n"); 1724 break; 1725 default: 1726 rc = -EIO; 1727 } 1728 else 1729 switch (cbctl->ipa_rc) { 1730 case IPA_RC_NOTSUPP: 1731 rc = -EOPNOTSUPP; 1732 break; 1733 case IPA_RC_UNSUPPORTED_COMMAND: 1734 rc = -EOPNOTSUPP; 1735 break; 1736 default: 1737 rc = -EIO; 1738 } 1739 1740 if (rc) { 1741 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc); 1742 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc); 1743 } 1744 return rc; 1745 } 1746 1747 static inline int ipa_cmd_sbp(struct qeth_card *card) 1748 { 1749 return (card->info.type == QETH_CARD_TYPE_IQD) ? 1750 IPA_CMD_SETBRIDGEPORT_IQD : 1751 IPA_CMD_SETBRIDGEPORT_OSA; 1752 } 1753 1754 static int qeth_bridgeport_query_support_cb(struct qeth_card *card, 1755 struct qeth_reply *reply, unsigned long data) 1756 { 1757 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1758 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; 1759 QETH_CARD_TEXT(card, 2, "brqsupcb"); 1760 cbctl->ipa_rc = cmd->hdr.return_code; 1761 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; 1762 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) { 1763 cbctl->data.supported = 1764 cmd->data.sbp.data.query_cmds_supp.supported_cmds; 1765 } else { 1766 cbctl->data.supported = 0; 1767 } 1768 return 0; 1769 } 1770 1771 /** 1772 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions. 1773 * @card: qeth_card structure pointer. 1774 * 1775 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card 1776 * strucutre: card->options.sbp.supported_funcs. 1777 */ 1778 static void qeth_bridgeport_query_support(struct qeth_card *card) 1779 { 1780 struct qeth_cmd_buffer *iob; 1781 struct qeth_ipa_cmd *cmd; 1782 struct _qeth_sbp_cbctl cbctl; 1783 1784 QETH_CARD_TEXT(card, 2, "brqsuppo"); 1785 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0); 1786 if (!iob) 1787 return; 1788 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); 1789 cmd->data.sbp.hdr.cmdlength = 1790 sizeof(struct qeth_ipacmd_sbp_hdr) + 1791 sizeof(struct qeth_sbp_query_cmds_supp); 1792 cmd->data.sbp.hdr.command_code = 1793 IPA_SBP_QUERY_COMMANDS_SUPPORTED; 1794 cmd->data.sbp.hdr.used_total = 1; 1795 cmd->data.sbp.hdr.seq_no = 1; 1796 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb, 1797 (void *)&cbctl) || 1798 qeth_bridgeport_makerc(card, &cbctl, 1799 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) { 1800 /* non-zero makerc signifies failure, and produce messages */ 1801 card->options.sbp.role = QETH_SBP_ROLE_NONE; 1802 return; 1803 } 1804 card->options.sbp.supported_funcs = cbctl.data.supported; 1805 } 1806 1807 static int qeth_bridgeport_query_ports_cb(struct qeth_card *card, 1808 struct qeth_reply *reply, unsigned long data) 1809 { 1810 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; 1811 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports; 1812 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; 1813 1814 QETH_CARD_TEXT(card, 2, "brqprtcb"); 1815 cbctl->ipa_rc = cmd->hdr.return_code; 1816 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; 1817 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0)) 1818 return 0; 1819 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { 1820 cbctl->cmd_rc = 0xffff; 1821 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length); 1822 return 0; 1823 } 1824 /* first entry contains the state of the local port */ 1825 if (qports->num_entries > 0) { 1826 if (cbctl->data.qports.role) 1827 *cbctl->data.qports.role = qports->entry[0].role; 1828 if (cbctl->data.qports.state) 1829 *cbctl->data.qports.state = qports->entry[0].state; 1830 } 1831 return 0; 1832 } 1833 1834 /** 1835 * qeth_bridgeport_query_ports() - query local bridgeport status. 1836 * @card: qeth_card structure pointer. 1837 * @role: Role of the port: 0-none, 1-primary, 2-secondary. 1838 * @state: State of the port: 0-inactive, 1-standby, 2-active. 1839 * 1840 * Returns negative errno-compatible error indication or 0 on success. 1841 * 1842 * 'role' and 'state' are not updated in case of hardware operation failure. 1843 */ 1844 int qeth_bridgeport_query_ports(struct qeth_card *card, 1845 enum qeth_sbp_roles *role, enum qeth_sbp_states *state) 1846 { 1847 int rc = 0; 1848 struct qeth_cmd_buffer *iob; 1849 struct qeth_ipa_cmd *cmd; 1850 struct _qeth_sbp_cbctl cbctl = { 1851 .data = { 1852 .qports = { 1853 .role = role, 1854 .state = state, 1855 }, 1856 }, 1857 }; 1858 1859 QETH_CARD_TEXT(card, 2, "brqports"); 1860 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS)) 1861 return -EOPNOTSUPP; 1862 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0); 1863 if (!iob) 1864 return -ENOMEM; 1865 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); 1866 cmd->data.sbp.hdr.cmdlength = 1867 sizeof(struct qeth_ipacmd_sbp_hdr); 1868 cmd->data.sbp.hdr.command_code = 1869 IPA_SBP_QUERY_BRIDGE_PORTS; 1870 cmd->data.sbp.hdr.used_total = 1; 1871 cmd->data.sbp.hdr.seq_no = 1; 1872 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb, 1873 (void *)&cbctl); 1874 if (rc < 0) 1875 return rc; 1876 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS); 1877 } 1878 EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports); 1879 1880 static int qeth_bridgeport_set_cb(struct qeth_card *card, 1881 struct qeth_reply *reply, unsigned long data) 1882 { 1883 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data; 1884 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; 1885 QETH_CARD_TEXT(card, 2, "brsetrcb"); 1886 cbctl->ipa_rc = cmd->hdr.return_code; 1887 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; 1888 return 0; 1889 } 1890 1891 /** 1892 * qeth_bridgeport_setrole() - Assign primary role to the port. 1893 * @card: qeth_card structure pointer. 1894 * @role: Role to assign. 1895 * 1896 * Returns negative errno-compatible error indication or 0 on success. 1897 */ 1898 int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role) 1899 { 1900 int rc = 0; 1901 int cmdlength; 1902 struct qeth_cmd_buffer *iob; 1903 struct qeth_ipa_cmd *cmd; 1904 struct _qeth_sbp_cbctl cbctl; 1905 enum qeth_ipa_sbp_cmd setcmd; 1906 1907 QETH_CARD_TEXT(card, 2, "brsetrol"); 1908 switch (role) { 1909 case QETH_SBP_ROLE_NONE: 1910 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE; 1911 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) + 1912 sizeof(struct qeth_sbp_reset_role); 1913 break; 1914 case QETH_SBP_ROLE_PRIMARY: 1915 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT; 1916 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) + 1917 sizeof(struct qeth_sbp_set_primary); 1918 break; 1919 case QETH_SBP_ROLE_SECONDARY: 1920 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT; 1921 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) + 1922 sizeof(struct qeth_sbp_set_secondary); 1923 break; 1924 default: 1925 return -EINVAL; 1926 } 1927 if (!(card->options.sbp.supported_funcs & setcmd)) 1928 return -EOPNOTSUPP; 1929 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0); 1930 if (!iob) 1931 return -ENOMEM; 1932 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); 1933 cmd->data.sbp.hdr.cmdlength = cmdlength; 1934 cmd->data.sbp.hdr.command_code = setcmd; 1935 cmd->data.sbp.hdr.used_total = 1; 1936 cmd->data.sbp.hdr.seq_no = 1; 1937 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, 1938 (void *)&cbctl); 1939 if (rc < 0) 1940 return rc; 1941 return qeth_bridgeport_makerc(card, &cbctl, setcmd); 1942 } 1943 1944 /** 1945 * qeth_anset_makerc() - derive "traditional" error from hardware codes. 1946 * @card: qeth_card structure pointer, for debug messages. 1947 * 1948 * Returns negative errno-compatible error indication or 0 on success. 1949 */ 1950 static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response) 1951 { 1952 int rc; 1953 1954 if (pnso_rc == 0) 1955 switch (response) { 1956 case 0x0001: 1957 rc = 0; 1958 break; 1959 case 0x0004: 1960 case 0x0100: 1961 case 0x0106: 1962 rc = -EOPNOTSUPP; 1963 dev_err(&card->gdev->dev, 1964 "Setting address notification failed\n"); 1965 break; 1966 case 0x0107: 1967 rc = -EAGAIN; 1968 break; 1969 default: 1970 rc = -EIO; 1971 } 1972 else 1973 rc = -EIO; 1974 1975 if (rc) { 1976 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc); 1977 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response); 1978 } 1979 return rc; 1980 } 1981 1982 static void qeth_bridgeport_an_set_cb(void *priv, 1983 enum qdio_brinfo_entry_type type, void *entry) 1984 { 1985 struct qeth_card *card = (struct qeth_card *)priv; 1986 struct qdio_brinfo_entry_l2 *l2entry; 1987 u8 code; 1988 1989 if (type != l2_addr_lnid) { 1990 WARN_ON_ONCE(1); 1991 return; 1992 } 1993 1994 l2entry = (struct qdio_brinfo_entry_l2 *)entry; 1995 code = IPA_ADDR_CHANGE_CODE_MACADDR; 1996 if (l2entry->addr_lnid.lnid) 1997 code |= IPA_ADDR_CHANGE_CODE_VLANID; 1998 qeth_bridge_emit_host_event(card, anev_reg_unreg, code, 1999 (struct net_if_token *)&l2entry->nit, 2000 (struct mac_addr_lnid *)&l2entry->addr_lnid); 2001 } 2002 2003 /** 2004 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification 2005 * @card: qeth_card structure pointer. 2006 * @enable: 0 - disable, non-zero - enable notifications 2007 * 2008 * Returns negative errno-compatible error indication or 0 on success. 2009 * 2010 * On enable, emits a series of address notifications udev events for all 2011 * currently registered hosts. 2012 */ 2013 int qeth_bridgeport_an_set(struct qeth_card *card, int enable) 2014 { 2015 int rc; 2016 u16 response; 2017 struct ccw_device *ddev; 2018 struct subchannel_id schid; 2019 2020 if (!card) 2021 return -EINVAL; 2022 if (!card->options.sbp.supported_funcs) 2023 return -EOPNOTSUPP; 2024 ddev = CARD_DDEV(card); 2025 ccw_device_get_schid(ddev, &schid); 2026 2027 if (enable) { 2028 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL); 2029 rc = qdio_pnso_brinfo(schid, 1, &response, 2030 qeth_bridgeport_an_set_cb, card); 2031 } else 2032 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL); 2033 return qeth_anset_makerc(card, rc, response); 2034 } 2035 EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set); 2036 2037 module_init(qeth_l2_init); 2038 module_exit(qeth_l2_exit); 2039 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); 2040 MODULE_DESCRIPTION("qeth layer 2 discipline"); 2041 MODULE_LICENSE("GPL"); 2042