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