1 /* 2 * drivers/s390/net/qeth_l2_main.c 3 * 4 * Copyright IBM Corp. 2007, 2009 5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>, 6 * Frank Pavlic <fpavlic@de.ibm.com>, 7 * Thomas Spatzier <tspat@de.ibm.com>, 8 * Frank Blaschka <frank.blaschka@de.ibm.com> 9 */ 10 11 #define KMSG_COMPONENT "qeth" 12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 13 14 #include <linux/module.h> 15 #include <linux/moduleparam.h> 16 #include <linux/string.h> 17 #include <linux/errno.h> 18 #include <linux/kernel.h> 19 #include <linux/slab.h> 20 #include <linux/etherdevice.h> 21 #include <linux/mii.h> 22 #include <linux/ip.h> 23 #include <linux/list.h> 24 25 #include "qeth_core.h" 26 27 static int qeth_l2_set_offline(struct ccwgroup_device *); 28 static int qeth_l2_stop(struct net_device *); 29 static int qeth_l2_send_delmac(struct qeth_card *, __u8 *); 30 static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *, 31 enum qeth_ipa_cmds, 32 int (*reply_cb) (struct qeth_card *, 33 struct qeth_reply*, 34 unsigned long)); 35 static void qeth_l2_set_multicast_list(struct net_device *); 36 static int qeth_l2_recover(void *); 37 38 static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 39 { 40 struct qeth_card *card = dev->ml_priv; 41 struct mii_ioctl_data *mii_data; 42 int rc = 0; 43 44 if (!card) 45 return -ENODEV; 46 47 if ((card->state != CARD_STATE_UP) && 48 (card->state != CARD_STATE_SOFTSETUP)) 49 return -ENODEV; 50 51 if (card->info.type == QETH_CARD_TYPE_OSN) 52 return -EPERM; 53 54 switch (cmd) { 55 case SIOC_QETH_ADP_SET_SNMP_CONTROL: 56 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data); 57 break; 58 case SIOC_QETH_GET_CARD_TYPE: 59 if ((card->info.type == QETH_CARD_TYPE_OSD || 60 card->info.type == QETH_CARD_TYPE_OSM || 61 card->info.type == QETH_CARD_TYPE_OSX) && 62 !card->info.guestlan) 63 return 1; 64 return 0; 65 break; 66 case SIOCGMIIPHY: 67 mii_data = if_mii(rq); 68 mii_data->phy_id = 0; 69 break; 70 case SIOCGMIIREG: 71 mii_data = if_mii(rq); 72 if (mii_data->phy_id != 0) 73 rc = -EINVAL; 74 else 75 mii_data->val_out = qeth_mdio_read(dev, 76 mii_data->phy_id, mii_data->reg_num); 77 break; 78 default: 79 rc = -EOPNOTSUPP; 80 } 81 if (rc) 82 QETH_CARD_TEXT_(card, 2, "ioce%d", rc); 83 return rc; 84 } 85 86 static int qeth_l2_verify_dev(struct net_device *dev) 87 { 88 struct qeth_card *card; 89 unsigned long flags; 90 int rc = 0; 91 92 read_lock_irqsave(&qeth_core_card_list.rwlock, flags); 93 list_for_each_entry(card, &qeth_core_card_list.list, list) { 94 if (card->dev == dev) { 95 rc = QETH_REAL_CARD; 96 break; 97 } 98 } 99 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); 100 101 return rc; 102 } 103 104 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no) 105 { 106 struct qeth_card *card; 107 struct net_device *ndev; 108 __u16 temp_dev_no; 109 unsigned long flags; 110 struct ccw_dev_id read_devid; 111 112 ndev = NULL; 113 memcpy(&temp_dev_no, read_dev_no, 2); 114 read_lock_irqsave(&qeth_core_card_list.rwlock, flags); 115 list_for_each_entry(card, &qeth_core_card_list.list, list) { 116 ccw_device_get_id(CARD_RDEV(card), &read_devid); 117 if (read_devid.devno == temp_dev_no) { 118 ndev = card->dev; 119 break; 120 } 121 } 122 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); 123 return ndev; 124 } 125 126 static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card, 127 struct qeth_reply *reply, 128 unsigned long data) 129 { 130 struct qeth_ipa_cmd *cmd; 131 __u8 *mac; 132 133 QETH_CARD_TEXT(card, 2, "L2Sgmacb"); 134 cmd = (struct qeth_ipa_cmd *) data; 135 mac = &cmd->data.setdelmac.mac[0]; 136 /* MAC already registered, needed in couple/uncouple case */ 137 if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) { 138 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n", 139 mac, QETH_CARD_IFNAME(card)); 140 cmd->hdr.return_code = 0; 141 } 142 if (cmd->hdr.return_code) 143 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n", 144 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code); 145 return 0; 146 } 147 148 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac) 149 { 150 QETH_CARD_TEXT(card, 2, "L2Sgmac"); 151 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC, 152 qeth_l2_send_setgroupmac_cb); 153 } 154 155 static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card, 156 struct qeth_reply *reply, 157 unsigned long data) 158 { 159 struct qeth_ipa_cmd *cmd; 160 __u8 *mac; 161 162 QETH_CARD_TEXT(card, 2, "L2Dgmacb"); 163 cmd = (struct qeth_ipa_cmd *) data; 164 mac = &cmd->data.setdelmac.mac[0]; 165 if (cmd->hdr.return_code) 166 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n", 167 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code); 168 return 0; 169 } 170 171 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac) 172 { 173 QETH_CARD_TEXT(card, 2, "L2Dgmac"); 174 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC, 175 qeth_l2_send_delgroupmac_cb); 176 } 177 178 static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac) 179 { 180 struct qeth_mc_mac *mc; 181 int rc; 182 183 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC); 184 185 if (!mc) 186 return; 187 188 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN); 189 mc->mc_addrlen = OSA_ADDR_LEN; 190 mc->is_vmac = vmac; 191 192 if (vmac) { 193 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC, 194 NULL); 195 } else { 196 rc = qeth_l2_send_setgroupmac(card, mac); 197 } 198 199 if (!rc) 200 list_add_tail(&mc->list, &card->mc_list); 201 else 202 kfree(mc); 203 } 204 205 static void qeth_l2_del_all_mc(struct qeth_card *card, int del) 206 { 207 struct qeth_mc_mac *mc, *tmp; 208 209 spin_lock_bh(&card->mclock); 210 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) { 211 if (del) { 212 if (mc->is_vmac) 213 qeth_l2_send_setdelmac(card, mc->mc_addr, 214 IPA_CMD_DELVMAC, NULL); 215 else 216 qeth_l2_send_delgroupmac(card, mc->mc_addr); 217 } 218 list_del(&mc->list); 219 kfree(mc); 220 } 221 spin_unlock_bh(&card->mclock); 222 } 223 224 static inline int qeth_l2_get_cast_type(struct qeth_card *card, 225 struct sk_buff *skb) 226 { 227 if (card->info.type == QETH_CARD_TYPE_OSN) 228 return RTN_UNSPEC; 229 if (is_broadcast_ether_addr(skb->data)) 230 return RTN_BROADCAST; 231 if (is_multicast_ether_addr(skb->data)) 232 return RTN_MULTICAST; 233 return RTN_UNSPEC; 234 } 235 236 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, 237 struct sk_buff *skb, int ipv, int cast_type) 238 { 239 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb); 240 241 memset(hdr, 0, sizeof(struct qeth_hdr)); 242 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; 243 244 /* set byte byte 3 to casting flags */ 245 if (cast_type == RTN_MULTICAST) 246 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST; 247 else if (cast_type == RTN_BROADCAST) 248 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST; 249 else 250 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST; 251 252 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE; 253 /* VSWITCH relies on the VLAN 254 * information to be present in 255 * the QDIO header */ 256 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) { 257 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN; 258 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI); 259 } 260 } 261 262 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card, 263 struct qeth_reply *reply, unsigned long data) 264 { 265 struct qeth_ipa_cmd *cmd; 266 267 QETH_CARD_TEXT(card, 2, "L2sdvcb"); 268 cmd = (struct qeth_ipa_cmd *) data; 269 if (cmd->hdr.return_code) { 270 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. " 271 "Continuing\n", cmd->data.setdelvlan.vlan_id, 272 QETH_CARD_IFNAME(card), cmd->hdr.return_code); 273 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command); 274 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code); 275 } 276 return 0; 277 } 278 279 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i, 280 enum qeth_ipa_cmds ipacmd) 281 { 282 struct qeth_ipa_cmd *cmd; 283 struct qeth_cmd_buffer *iob; 284 285 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd); 286 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); 287 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); 288 cmd->data.setdelvlan.vlan_id = i; 289 return qeth_send_ipa_cmd(card, iob, 290 qeth_l2_send_setdelvlan_cb, NULL); 291 } 292 293 static void qeth_l2_process_vlans(struct qeth_card *card) 294 { 295 struct qeth_vlan_vid *id; 296 QETH_CARD_TEXT(card, 3, "L2prcvln"); 297 spin_lock_bh(&card->vlanlock); 298 list_for_each_entry(id, &card->vid_list, list) { 299 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN); 300 } 301 spin_unlock_bh(&card->vlanlock); 302 } 303 304 static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) 305 { 306 struct qeth_card *card = dev->ml_priv; 307 struct qeth_vlan_vid *id; 308 309 QETH_CARD_TEXT_(card, 4, "aid:%d", vid); 310 if (!vid) 311 return; 312 if (card->info.type == QETH_CARD_TYPE_OSM) { 313 QETH_CARD_TEXT(card, 3, "aidOSM"); 314 return; 315 } 316 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { 317 QETH_CARD_TEXT(card, 3, "aidREC"); 318 return; 319 } 320 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC); 321 if (id) { 322 id->vid = vid; 323 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); 324 spin_lock_bh(&card->vlanlock); 325 list_add_tail(&id->list, &card->vid_list); 326 spin_unlock_bh(&card->vlanlock); 327 } 328 } 329 330 static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) 331 { 332 struct qeth_vlan_vid *id, *tmpid = NULL; 333 struct qeth_card *card = dev->ml_priv; 334 335 QETH_CARD_TEXT_(card, 4, "kid:%d", vid); 336 if (card->info.type == QETH_CARD_TYPE_OSM) { 337 QETH_CARD_TEXT(card, 3, "kidOSM"); 338 return; 339 } 340 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { 341 QETH_CARD_TEXT(card, 3, "kidREC"); 342 return; 343 } 344 spin_lock_bh(&card->vlanlock); 345 list_for_each_entry(id, &card->vid_list, list) { 346 if (id->vid == vid) { 347 list_del(&id->list); 348 tmpid = id; 349 break; 350 } 351 } 352 spin_unlock_bh(&card->vlanlock); 353 if (tmpid) { 354 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); 355 kfree(tmpid); 356 } 357 qeth_l2_set_multicast_list(card->dev); 358 } 359 360 static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode) 361 { 362 int rc = 0; 363 364 QETH_DBF_TEXT(SETUP , 2, "stopcard"); 365 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); 366 367 qeth_set_allowed_threads(card, 0, 1); 368 if (card->read.state == CH_STATE_UP && 369 card->write.state == CH_STATE_UP && 370 (card->state == CARD_STATE_UP)) { 371 if (recovery_mode && 372 card->info.type != QETH_CARD_TYPE_OSN) { 373 qeth_l2_stop(card->dev); 374 } else { 375 rtnl_lock(); 376 dev_close(card->dev); 377 rtnl_unlock(); 378 } 379 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; 380 card->state = CARD_STATE_SOFTSETUP; 381 } 382 if (card->state == CARD_STATE_SOFTSETUP) { 383 qeth_l2_del_all_mc(card, 0); 384 qeth_clear_ipacmd_list(card); 385 card->state = CARD_STATE_HARDSETUP; 386 } 387 if (card->state == CARD_STATE_HARDSETUP) { 388 qeth_qdio_clear_card(card, 0); 389 qeth_clear_qdio_buffers(card); 390 qeth_clear_working_pool_list(card); 391 card->state = CARD_STATE_DOWN; 392 } 393 if (card->state == CARD_STATE_DOWN) { 394 qeth_clear_cmd_buffers(&card->read); 395 qeth_clear_cmd_buffers(&card->write); 396 } 397 return rc; 398 } 399 400 static int qeth_l2_process_inbound_buffer(struct qeth_card *card, 401 int budget, int *done) 402 { 403 int work_done = 0; 404 struct sk_buff *skb; 405 struct qeth_hdr *hdr; 406 unsigned int len; 407 408 *done = 0; 409 BUG_ON(!budget); 410 while (budget) { 411 skb = qeth_core_get_next_skb(card, 412 &card->qdio.in_q->bufs[card->rx.b_index], 413 &card->rx.b_element, &card->rx.e_offset, &hdr); 414 if (!skb) { 415 *done = 1; 416 break; 417 } 418 skb->dev = card->dev; 419 switch (hdr->hdr.l2.id) { 420 case QETH_HEADER_TYPE_LAYER2: 421 skb->pkt_type = PACKET_HOST; 422 skb->protocol = eth_type_trans(skb, skb->dev); 423 skb->ip_summed = CHECKSUM_NONE; 424 if (skb->protocol == htons(ETH_P_802_2)) 425 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno; 426 len = skb->len; 427 netif_receive_skb(skb); 428 break; 429 case QETH_HEADER_TYPE_OSN: 430 if (card->info.type == QETH_CARD_TYPE_OSN) { 431 skb_push(skb, sizeof(struct qeth_hdr)); 432 skb_copy_to_linear_data(skb, hdr, 433 sizeof(struct qeth_hdr)); 434 len = skb->len; 435 card->osn_info.data_cb(skb); 436 break; 437 } 438 /* else unknown */ 439 default: 440 dev_kfree_skb_any(skb); 441 QETH_CARD_TEXT(card, 3, "inbunkno"); 442 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN); 443 continue; 444 } 445 work_done++; 446 budget--; 447 card->stats.rx_packets++; 448 card->stats.rx_bytes += len; 449 } 450 return work_done; 451 } 452 453 static int qeth_l2_poll(struct napi_struct *napi, int budget) 454 { 455 struct qeth_card *card = container_of(napi, struct qeth_card, napi); 456 int work_done = 0; 457 struct qeth_qdio_buffer *buffer; 458 int done; 459 int new_budget = budget; 460 461 if (card->options.performance_stats) { 462 card->perf_stats.inbound_cnt++; 463 card->perf_stats.inbound_start_time = qeth_get_micros(); 464 } 465 466 while (1) { 467 if (!card->rx.b_count) { 468 card->rx.qdio_err = 0; 469 card->rx.b_count = qdio_get_next_buffers( 470 card->data.ccwdev, 0, &card->rx.b_index, 471 &card->rx.qdio_err); 472 if (card->rx.b_count <= 0) { 473 card->rx.b_count = 0; 474 break; 475 } 476 card->rx.b_element = 477 &card->qdio.in_q->bufs[card->rx.b_index] 478 .buffer->element[0]; 479 card->rx.e_offset = 0; 480 } 481 482 while (card->rx.b_count) { 483 buffer = &card->qdio.in_q->bufs[card->rx.b_index]; 484 if (!(card->rx.qdio_err && 485 qeth_check_qdio_errors(card, buffer->buffer, 486 card->rx.qdio_err, "qinerr"))) 487 work_done += qeth_l2_process_inbound_buffer( 488 card, new_budget, &done); 489 else 490 done = 1; 491 492 if (done) { 493 if (card->options.performance_stats) 494 card->perf_stats.bufs_rec++; 495 qeth_put_buffer_pool_entry(card, 496 buffer->pool_entry); 497 qeth_queue_input_buffer(card, card->rx.b_index); 498 card->rx.b_count--; 499 if (card->rx.b_count) { 500 card->rx.b_index = 501 (card->rx.b_index + 1) % 502 QDIO_MAX_BUFFERS_PER_Q; 503 card->rx.b_element = 504 &card->qdio.in_q 505 ->bufs[card->rx.b_index] 506 .buffer->element[0]; 507 card->rx.e_offset = 0; 508 } 509 } 510 511 if (work_done >= budget) 512 goto out; 513 else 514 new_budget = budget - work_done; 515 } 516 } 517 518 napi_complete(napi); 519 if (qdio_start_irq(card->data.ccwdev, 0)) 520 napi_schedule(&card->napi); 521 out: 522 if (card->options.performance_stats) 523 card->perf_stats.inbound_time += qeth_get_micros() - 524 card->perf_stats.inbound_start_time; 525 return work_done; 526 } 527 528 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac, 529 enum qeth_ipa_cmds ipacmd, 530 int (*reply_cb) (struct qeth_card *, 531 struct qeth_reply*, 532 unsigned long)) 533 { 534 struct qeth_ipa_cmd *cmd; 535 struct qeth_cmd_buffer *iob; 536 537 QETH_CARD_TEXT(card, 2, "L2sdmac"); 538 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); 539 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); 540 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN; 541 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN); 542 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL); 543 } 544 545 static int qeth_l2_send_setmac_cb(struct qeth_card *card, 546 struct qeth_reply *reply, 547 unsigned long data) 548 { 549 struct qeth_ipa_cmd *cmd; 550 551 QETH_CARD_TEXT(card, 2, "L2Smaccb"); 552 cmd = (struct qeth_ipa_cmd *) data; 553 if (cmd->hdr.return_code) { 554 QETH_CARD_TEXT_(card, 2, "L2er%x", cmd->hdr.return_code); 555 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; 556 switch (cmd->hdr.return_code) { 557 case IPA_RC_L2_DUP_MAC: 558 case IPA_RC_L2_DUP_LAYER3_MAC: 559 dev_warn(&card->gdev->dev, 560 "MAC address %pM already exists\n", 561 cmd->data.setdelmac.mac); 562 break; 563 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP: 564 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: 565 dev_warn(&card->gdev->dev, 566 "MAC address %pM is not authorized\n", 567 cmd->data.setdelmac.mac); 568 break; 569 default: 570 break; 571 } 572 cmd->hdr.return_code = -EIO; 573 } else { 574 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED; 575 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac, 576 OSA_ADDR_LEN); 577 dev_info(&card->gdev->dev, 578 "MAC address %pM successfully registered on device %s\n", 579 card->dev->dev_addr, card->dev->name); 580 } 581 return 0; 582 } 583 584 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac) 585 { 586 QETH_CARD_TEXT(card, 2, "L2Setmac"); 587 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC, 588 qeth_l2_send_setmac_cb); 589 } 590 591 static int qeth_l2_send_delmac_cb(struct qeth_card *card, 592 struct qeth_reply *reply, 593 unsigned long data) 594 { 595 struct qeth_ipa_cmd *cmd; 596 597 QETH_CARD_TEXT(card, 2, "L2Dmaccb"); 598 cmd = (struct qeth_ipa_cmd *) data; 599 if (cmd->hdr.return_code) { 600 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code); 601 cmd->hdr.return_code = -EIO; 602 return 0; 603 } 604 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; 605 606 return 0; 607 } 608 609 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac) 610 { 611 QETH_CARD_TEXT(card, 2, "L2Delmac"); 612 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)) 613 return 0; 614 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC, 615 qeth_l2_send_delmac_cb); 616 } 617 618 static int qeth_l2_request_initial_mac(struct qeth_card *card) 619 { 620 int rc = 0; 621 char vendor_pre[] = {0x02, 0x00, 0x00}; 622 623 QETH_DBF_TEXT(SETUP, 2, "doL2init"); 624 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card)); 625 626 rc = qeth_query_setadapterparms(card); 627 if (rc) { 628 QETH_DBF_MESSAGE(2, "could not query adapter parameters on " 629 "device %s: x%x\n", CARD_BUS_ID(card), rc); 630 } 631 632 if (card->info.type == QETH_CARD_TYPE_IQD || 633 card->info.type == QETH_CARD_TYPE_OSM || 634 card->info.type == QETH_CARD_TYPE_OSX || 635 card->info.guestlan) { 636 rc = qeth_setadpparms_change_macaddr(card); 637 if (rc) { 638 QETH_DBF_MESSAGE(2, "couldn't get MAC address on " 639 "device %s: x%x\n", CARD_BUS_ID(card), rc); 640 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); 641 return rc; 642 } 643 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN); 644 } else { 645 random_ether_addr(card->dev->dev_addr); 646 memcpy(card->dev->dev_addr, vendor_pre, 3); 647 } 648 return 0; 649 } 650 651 static int qeth_l2_set_mac_address(struct net_device *dev, void *p) 652 { 653 struct sockaddr *addr = p; 654 struct qeth_card *card = dev->ml_priv; 655 int rc = 0; 656 657 QETH_CARD_TEXT(card, 3, "setmac"); 658 659 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) { 660 QETH_CARD_TEXT(card, 3, "setmcINV"); 661 return -EOPNOTSUPP; 662 } 663 664 if (card->info.type == QETH_CARD_TYPE_OSN || 665 card->info.type == QETH_CARD_TYPE_OSM || 666 card->info.type == QETH_CARD_TYPE_OSX) { 667 QETH_CARD_TEXT(card, 3, "setmcTYP"); 668 return -EOPNOTSUPP; 669 } 670 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN); 671 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { 672 QETH_CARD_TEXT(card, 3, "setmcREC"); 673 return -ERESTARTSYS; 674 } 675 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]); 676 if (!rc) 677 rc = qeth_l2_send_setmac(card, addr->sa_data); 678 return rc; 679 } 680 681 static void qeth_l2_set_multicast_list(struct net_device *dev) 682 { 683 struct qeth_card *card = dev->ml_priv; 684 struct netdev_hw_addr *ha; 685 686 if (card->info.type == QETH_CARD_TYPE_OSN) 687 return ; 688 689 QETH_CARD_TEXT(card, 3, "setmulti"); 690 if (qeth_threads_running(card, QETH_RECOVER_THREAD) && 691 (card->state != CARD_STATE_UP)) 692 return; 693 qeth_l2_del_all_mc(card, 1); 694 spin_lock_bh(&card->mclock); 695 netdev_for_each_mc_addr(ha, dev) 696 qeth_l2_add_mc(card, ha->addr, 0); 697 698 netdev_for_each_uc_addr(ha, dev) 699 qeth_l2_add_mc(card, ha->addr, 1); 700 701 spin_unlock_bh(&card->mclock); 702 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) 703 return; 704 qeth_setadp_promisc_mode(card); 705 } 706 707 static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) 708 { 709 int rc; 710 struct qeth_hdr *hdr = NULL; 711 int elements = 0; 712 struct qeth_card *card = dev->ml_priv; 713 struct sk_buff *new_skb = skb; 714 int ipv = qeth_get_ip_version(skb); 715 int cast_type = qeth_l2_get_cast_type(card, skb); 716 struct qeth_qdio_out_q *queue = card->qdio.out_qs 717 [qeth_get_priority_queue(card, skb, ipv, cast_type)]; 718 int tx_bytes = skb->len; 719 int data_offset = -1; 720 int elements_needed = 0; 721 int hd_len = 0; 722 723 if ((card->state != CARD_STATE_UP) || !card->lan_online) { 724 card->stats.tx_carrier_errors++; 725 goto tx_drop; 726 } 727 728 if ((card->info.type == QETH_CARD_TYPE_OSN) && 729 (skb->protocol == htons(ETH_P_IPV6))) 730 goto tx_drop; 731 732 if (card->options.performance_stats) { 733 card->perf_stats.outbound_cnt++; 734 card->perf_stats.outbound_start_time = qeth_get_micros(); 735 } 736 netif_stop_queue(dev); 737 738 if (card->info.type == QETH_CARD_TYPE_OSN) 739 hdr = (struct qeth_hdr *)skb->data; 740 else { 741 if (card->info.type == QETH_CARD_TYPE_IQD) { 742 new_skb = skb; 743 data_offset = ETH_HLEN; 744 hd_len = ETH_HLEN; 745 hdr = kmem_cache_alloc(qeth_core_header_cache, 746 GFP_ATOMIC); 747 if (!hdr) 748 goto tx_drop; 749 elements_needed++; 750 skb_reset_mac_header(new_skb); 751 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type); 752 hdr->hdr.l2.pkt_length = new_skb->len; 753 memcpy(((char *)hdr) + sizeof(struct qeth_hdr), 754 skb_mac_header(new_skb), ETH_HLEN); 755 } else { 756 /* create a clone with writeable headroom */ 757 new_skb = skb_realloc_headroom(skb, 758 sizeof(struct qeth_hdr)); 759 if (!new_skb) 760 goto tx_drop; 761 hdr = (struct qeth_hdr *)skb_push(new_skb, 762 sizeof(struct qeth_hdr)); 763 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr)); 764 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type); 765 } 766 } 767 768 elements = qeth_get_elements_no(card, (void *)hdr, new_skb, 769 elements_needed); 770 if (!elements) { 771 if (data_offset >= 0) 772 kmem_cache_free(qeth_core_header_cache, hdr); 773 goto tx_drop; 774 } 775 776 if (card->info.type != QETH_CARD_TYPE_IQD) { 777 if (qeth_hdr_chk_and_bounce(new_skb, 778 sizeof(struct qeth_hdr_layer2))) 779 goto tx_drop; 780 rc = qeth_do_send_packet(card, queue, new_skb, hdr, 781 elements); 782 } else 783 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr, 784 elements, data_offset, hd_len); 785 if (!rc) { 786 card->stats.tx_packets++; 787 card->stats.tx_bytes += tx_bytes; 788 if (new_skb != skb) 789 dev_kfree_skb_any(skb); 790 rc = NETDEV_TX_OK; 791 } else { 792 if (data_offset >= 0) 793 kmem_cache_free(qeth_core_header_cache, hdr); 794 795 if (rc == -EBUSY) { 796 if (new_skb != skb) 797 dev_kfree_skb_any(new_skb); 798 return NETDEV_TX_BUSY; 799 } else 800 goto tx_drop; 801 } 802 803 netif_wake_queue(dev); 804 if (card->options.performance_stats) 805 card->perf_stats.outbound_time += qeth_get_micros() - 806 card->perf_stats.outbound_start_time; 807 return rc; 808 809 tx_drop: 810 card->stats.tx_dropped++; 811 card->stats.tx_errors++; 812 if ((new_skb != skb) && new_skb) 813 dev_kfree_skb_any(new_skb); 814 dev_kfree_skb_any(skb); 815 netif_wake_queue(dev); 816 return NETDEV_TX_OK; 817 } 818 819 static int __qeth_l2_open(struct net_device *dev) 820 { 821 struct qeth_card *card = dev->ml_priv; 822 int rc = 0; 823 824 QETH_CARD_TEXT(card, 4, "qethopen"); 825 if (card->state == CARD_STATE_UP) 826 return rc; 827 if (card->state != CARD_STATE_SOFTSETUP) 828 return -ENODEV; 829 830 if ((card->info.type != QETH_CARD_TYPE_OSN) && 831 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) { 832 QETH_CARD_TEXT(card, 4, "nomacadr"); 833 return -EPERM; 834 } 835 card->data.state = CH_STATE_UP; 836 card->state = CARD_STATE_UP; 837 netif_start_queue(dev); 838 839 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) { 840 napi_enable(&card->napi); 841 napi_schedule(&card->napi); 842 } else 843 rc = -EIO; 844 return rc; 845 } 846 847 static int qeth_l2_open(struct net_device *dev) 848 { 849 struct qeth_card *card = dev->ml_priv; 850 851 QETH_CARD_TEXT(card, 5, "qethope_"); 852 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { 853 QETH_CARD_TEXT(card, 3, "openREC"); 854 return -ERESTARTSYS; 855 } 856 return __qeth_l2_open(dev); 857 } 858 859 static int qeth_l2_stop(struct net_device *dev) 860 { 861 struct qeth_card *card = dev->ml_priv; 862 863 QETH_CARD_TEXT(card, 4, "qethstop"); 864 netif_tx_disable(dev); 865 if (card->state == CARD_STATE_UP) { 866 card->state = CARD_STATE_SOFTSETUP; 867 napi_disable(&card->napi); 868 } 869 return 0; 870 } 871 872 static int qeth_l2_probe_device(struct ccwgroup_device *gdev) 873 { 874 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 875 876 INIT_LIST_HEAD(&card->vid_list); 877 INIT_LIST_HEAD(&card->mc_list); 878 card->options.layer2 = 1; 879 card->info.hwtrap = 0; 880 card->discipline.start_poll = qeth_qdio_start_poll; 881 card->discipline.input_handler = (qdio_handler_t *) 882 qeth_qdio_input_handler; 883 card->discipline.output_handler = (qdio_handler_t *) 884 qeth_qdio_output_handler; 885 card->discipline.recover = qeth_l2_recover; 886 return 0; 887 } 888 889 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev) 890 { 891 struct qeth_card *card = dev_get_drvdata(&cgdev->dev); 892 893 qeth_set_allowed_threads(card, 0, 1); 894 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); 895 896 if (cgdev->state == CCWGROUP_ONLINE) 897 qeth_l2_set_offline(cgdev); 898 899 if (card->dev) { 900 unregister_netdev(card->dev); 901 card->dev = NULL; 902 } 903 return; 904 } 905 906 static const struct ethtool_ops qeth_l2_ethtool_ops = { 907 .get_link = ethtool_op_get_link, 908 .get_strings = qeth_core_get_strings, 909 .get_ethtool_stats = qeth_core_get_ethtool_stats, 910 .get_sset_count = qeth_core_get_sset_count, 911 .get_drvinfo = qeth_core_get_drvinfo, 912 .get_settings = qeth_core_ethtool_get_settings, 913 }; 914 915 static const struct ethtool_ops qeth_l2_osn_ops = { 916 .get_strings = qeth_core_get_strings, 917 .get_ethtool_stats = qeth_core_get_ethtool_stats, 918 .get_sset_count = qeth_core_get_sset_count, 919 .get_drvinfo = qeth_core_get_drvinfo, 920 }; 921 922 static const struct net_device_ops qeth_l2_netdev_ops = { 923 .ndo_open = qeth_l2_open, 924 .ndo_stop = qeth_l2_stop, 925 .ndo_get_stats = qeth_get_stats, 926 .ndo_start_xmit = qeth_l2_hard_start_xmit, 927 .ndo_validate_addr = eth_validate_addr, 928 .ndo_set_rx_mode = qeth_l2_set_multicast_list, 929 .ndo_do_ioctl = qeth_l2_do_ioctl, 930 .ndo_set_mac_address = qeth_l2_set_mac_address, 931 .ndo_change_mtu = qeth_change_mtu, 932 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid, 933 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid, 934 .ndo_tx_timeout = qeth_tx_timeout, 935 }; 936 937 static int qeth_l2_setup_netdev(struct qeth_card *card) 938 { 939 switch (card->info.type) { 940 case QETH_CARD_TYPE_IQD: 941 card->dev = alloc_netdev(0, "hsi%d", ether_setup); 942 break; 943 case QETH_CARD_TYPE_OSN: 944 card->dev = alloc_netdev(0, "osn%d", ether_setup); 945 card->dev->flags |= IFF_NOARP; 946 break; 947 default: 948 card->dev = alloc_etherdev(0); 949 } 950 951 if (!card->dev) 952 return -ENODEV; 953 954 card->dev->ml_priv = card; 955 card->dev->watchdog_timeo = QETH_TX_TIMEOUT; 956 card->dev->mtu = card->info.initial_mtu; 957 card->dev->netdev_ops = &qeth_l2_netdev_ops; 958 if (card->info.type != QETH_CARD_TYPE_OSN) 959 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops); 960 else 961 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops); 962 card->dev->features |= NETIF_F_HW_VLAN_FILTER; 963 card->info.broadcast_capable = 1; 964 qeth_l2_request_initial_mac(card); 965 SET_NETDEV_DEV(card->dev, &card->gdev->dev); 966 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT); 967 return register_netdev(card->dev); 968 } 969 970 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode) 971 { 972 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 973 int rc = 0; 974 enum qeth_card_states recover_flag; 975 976 BUG_ON(!card); 977 mutex_lock(&card->discipline_mutex); 978 mutex_lock(&card->conf_mutex); 979 QETH_DBF_TEXT(SETUP, 2, "setonlin"); 980 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); 981 982 recover_flag = card->state; 983 rc = qeth_core_hardsetup_card(card); 984 if (rc) { 985 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc); 986 rc = -ENODEV; 987 goto out_remove; 988 } 989 990 if (!card->dev && qeth_l2_setup_netdev(card)) { 991 rc = -ENODEV; 992 goto out_remove; 993 } 994 995 if (card->info.type != QETH_CARD_TYPE_OSN) 996 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]); 997 998 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) { 999 if (card->info.hwtrap && 1000 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)) 1001 card->info.hwtrap = 0; 1002 } else 1003 card->info.hwtrap = 0; 1004 1005 card->state = CARD_STATE_HARDSETUP; 1006 memset(&card->rx, 0, sizeof(struct qeth_rx)); 1007 qeth_print_status_message(card); 1008 1009 /* softsetup */ 1010 QETH_DBF_TEXT(SETUP, 2, "softsetp"); 1011 1012 rc = qeth_send_startlan(card); 1013 if (rc) { 1014 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); 1015 if (rc == 0xe080) { 1016 dev_warn(&card->gdev->dev, 1017 "The LAN is offline\n"); 1018 card->lan_online = 0; 1019 goto contin; 1020 } 1021 rc = -ENODEV; 1022 goto out_remove; 1023 } else 1024 card->lan_online = 1; 1025 1026 contin: 1027 if ((card->info.type == QETH_CARD_TYPE_OSD) || 1028 (card->info.type == QETH_CARD_TYPE_OSX)) 1029 /* configure isolation level */ 1030 qeth_set_access_ctrl_online(card); 1031 1032 if (card->info.type != QETH_CARD_TYPE_OSN && 1033 card->info.type != QETH_CARD_TYPE_OSM) 1034 qeth_l2_process_vlans(card); 1035 1036 netif_tx_disable(card->dev); 1037 1038 rc = qeth_init_qdio_queues(card); 1039 if (rc) { 1040 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc); 1041 rc = -ENODEV; 1042 goto out_remove; 1043 } 1044 card->state = CARD_STATE_SOFTSETUP; 1045 if (card->lan_online) 1046 netif_carrier_on(card->dev); 1047 else 1048 netif_carrier_off(card->dev); 1049 1050 qeth_set_allowed_threads(card, 0xffffffff, 0); 1051 if (recover_flag == CARD_STATE_RECOVER) { 1052 if (recovery_mode && 1053 card->info.type != QETH_CARD_TYPE_OSN) { 1054 __qeth_l2_open(card->dev); 1055 } else { 1056 rtnl_lock(); 1057 dev_open(card->dev); 1058 rtnl_unlock(); 1059 } 1060 /* this also sets saved unicast addresses */ 1061 qeth_l2_set_multicast_list(card->dev); 1062 } 1063 /* let user_space know that device is online */ 1064 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); 1065 mutex_unlock(&card->conf_mutex); 1066 mutex_unlock(&card->discipline_mutex); 1067 return 0; 1068 1069 out_remove: 1070 qeth_l2_stop_card(card, 0); 1071 ccw_device_set_offline(CARD_DDEV(card)); 1072 ccw_device_set_offline(CARD_WDEV(card)); 1073 ccw_device_set_offline(CARD_RDEV(card)); 1074 if (recover_flag == CARD_STATE_RECOVER) 1075 card->state = CARD_STATE_RECOVER; 1076 else 1077 card->state = CARD_STATE_DOWN; 1078 mutex_unlock(&card->conf_mutex); 1079 mutex_unlock(&card->discipline_mutex); 1080 return rc; 1081 } 1082 1083 static int qeth_l2_set_online(struct ccwgroup_device *gdev) 1084 { 1085 return __qeth_l2_set_online(gdev, 0); 1086 } 1087 1088 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev, 1089 int recovery_mode) 1090 { 1091 struct qeth_card *card = dev_get_drvdata(&cgdev->dev); 1092 int rc = 0, rc2 = 0, rc3 = 0; 1093 enum qeth_card_states recover_flag; 1094 1095 mutex_lock(&card->discipline_mutex); 1096 mutex_lock(&card->conf_mutex); 1097 QETH_DBF_TEXT(SETUP, 3, "setoffl"); 1098 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *)); 1099 1100 if (card->dev && netif_carrier_ok(card->dev)) 1101 netif_carrier_off(card->dev); 1102 recover_flag = card->state; 1103 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) { 1104 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 1105 card->info.hwtrap = 1; 1106 } 1107 qeth_l2_stop_card(card, recovery_mode); 1108 rc = ccw_device_set_offline(CARD_DDEV(card)); 1109 rc2 = ccw_device_set_offline(CARD_WDEV(card)); 1110 rc3 = ccw_device_set_offline(CARD_RDEV(card)); 1111 if (!rc) 1112 rc = (rc2) ? rc2 : rc3; 1113 if (rc) 1114 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); 1115 if (recover_flag == CARD_STATE_UP) 1116 card->state = CARD_STATE_RECOVER; 1117 /* let user_space know that device is offline */ 1118 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE); 1119 mutex_unlock(&card->conf_mutex); 1120 mutex_unlock(&card->discipline_mutex); 1121 return 0; 1122 } 1123 1124 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev) 1125 { 1126 return __qeth_l2_set_offline(cgdev, 0); 1127 } 1128 1129 static int qeth_l2_recover(void *ptr) 1130 { 1131 struct qeth_card *card; 1132 int rc = 0; 1133 1134 card = (struct qeth_card *) ptr; 1135 QETH_CARD_TEXT(card, 2, "recover1"); 1136 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) 1137 return 0; 1138 QETH_CARD_TEXT(card, 2, "recover2"); 1139 dev_warn(&card->gdev->dev, 1140 "A recovery process has been started for the device\n"); 1141 __qeth_l2_set_offline(card->gdev, 1); 1142 rc = __qeth_l2_set_online(card->gdev, 1); 1143 if (!rc) 1144 dev_info(&card->gdev->dev, 1145 "Device successfully recovered!\n"); 1146 else { 1147 rtnl_lock(); 1148 dev_close(card->dev); 1149 rtnl_unlock(); 1150 dev_warn(&card->gdev->dev, "The qeth device driver " 1151 "failed to recover an error on the device\n"); 1152 } 1153 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); 1154 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); 1155 return 0; 1156 } 1157 1158 static int __init qeth_l2_init(void) 1159 { 1160 pr_info("register layer 2 discipline\n"); 1161 return 0; 1162 } 1163 1164 static void __exit qeth_l2_exit(void) 1165 { 1166 pr_info("unregister layer 2 discipline\n"); 1167 } 1168 1169 static void qeth_l2_shutdown(struct ccwgroup_device *gdev) 1170 { 1171 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 1172 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap) 1173 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 1174 qeth_qdio_clear_card(card, 0); 1175 qeth_clear_qdio_buffers(card); 1176 } 1177 1178 static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev) 1179 { 1180 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 1181 1182 if (card->dev) 1183 netif_device_detach(card->dev); 1184 qeth_set_allowed_threads(card, 0, 1); 1185 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); 1186 if (gdev->state == CCWGROUP_OFFLINE) 1187 return 0; 1188 if (card->state == CARD_STATE_UP) { 1189 if (card->info.hwtrap) 1190 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 1191 __qeth_l2_set_offline(card->gdev, 1); 1192 } else 1193 __qeth_l2_set_offline(card->gdev, 0); 1194 return 0; 1195 } 1196 1197 static int qeth_l2_pm_resume(struct ccwgroup_device *gdev) 1198 { 1199 struct qeth_card *card = dev_get_drvdata(&gdev->dev); 1200 int rc = 0; 1201 1202 if (gdev->state == CCWGROUP_OFFLINE) 1203 goto out; 1204 1205 if (card->state == CARD_STATE_RECOVER) { 1206 rc = __qeth_l2_set_online(card->gdev, 1); 1207 if (rc) { 1208 rtnl_lock(); 1209 dev_close(card->dev); 1210 rtnl_unlock(); 1211 } 1212 } else 1213 rc = __qeth_l2_set_online(card->gdev, 0); 1214 out: 1215 qeth_set_allowed_threads(card, 0xffffffff, 0); 1216 if (card->dev) 1217 netif_device_attach(card->dev); 1218 if (rc) 1219 dev_warn(&card->gdev->dev, "The qeth device driver " 1220 "failed to recover an error on the device\n"); 1221 return rc; 1222 } 1223 1224 struct ccwgroup_driver qeth_l2_ccwgroup_driver = { 1225 .probe = qeth_l2_probe_device, 1226 .remove = qeth_l2_remove_device, 1227 .set_online = qeth_l2_set_online, 1228 .set_offline = qeth_l2_set_offline, 1229 .shutdown = qeth_l2_shutdown, 1230 .freeze = qeth_l2_pm_suspend, 1231 .thaw = qeth_l2_pm_resume, 1232 .restore = qeth_l2_pm_resume, 1233 }; 1234 EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver); 1235 1236 static int qeth_osn_send_control_data(struct qeth_card *card, int len, 1237 struct qeth_cmd_buffer *iob) 1238 { 1239 unsigned long flags; 1240 int rc = 0; 1241 1242 QETH_CARD_TEXT(card, 5, "osndctrd"); 1243 1244 wait_event(card->wait_q, 1245 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); 1246 qeth_prepare_control_data(card, len, iob); 1247 QETH_CARD_TEXT(card, 6, "osnoirqp"); 1248 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); 1249 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, 1250 (addr_t) iob, 0, 0); 1251 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); 1252 if (rc) { 1253 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: " 1254 "ccw_device_start rc = %i\n", rc); 1255 QETH_CARD_TEXT_(card, 2, " err%d", rc); 1256 qeth_release_buffer(iob->channel, iob); 1257 atomic_set(&card->write.irq_pending, 0); 1258 wake_up(&card->wait_q); 1259 } 1260 return rc; 1261 } 1262 1263 static int qeth_osn_send_ipa_cmd(struct qeth_card *card, 1264 struct qeth_cmd_buffer *iob, int data_len) 1265 { 1266 u16 s1, s2; 1267 1268 QETH_CARD_TEXT(card, 4, "osndipa"); 1269 1270 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2); 1271 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len); 1272 s2 = (u16)data_len; 1273 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); 1274 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); 1275 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); 1276 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); 1277 return qeth_osn_send_control_data(card, s1, iob); 1278 } 1279 1280 int qeth_osn_assist(struct net_device *dev, void *data, int data_len) 1281 { 1282 struct qeth_cmd_buffer *iob; 1283 struct qeth_card *card; 1284 int rc; 1285 1286 if (!dev) 1287 return -ENODEV; 1288 card = dev->ml_priv; 1289 if (!card) 1290 return -ENODEV; 1291 QETH_CARD_TEXT(card, 2, "osnsdmc"); 1292 if ((card->state != CARD_STATE_UP) && 1293 (card->state != CARD_STATE_SOFTSETUP)) 1294 return -ENODEV; 1295 iob = qeth_wait_for_buffer(&card->write); 1296 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len); 1297 rc = qeth_osn_send_ipa_cmd(card, iob, data_len); 1298 return rc; 1299 } 1300 EXPORT_SYMBOL(qeth_osn_assist); 1301 1302 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev, 1303 int (*assist_cb)(struct net_device *, void *), 1304 int (*data_cb)(struct sk_buff *)) 1305 { 1306 struct qeth_card *card; 1307 1308 *dev = qeth_l2_netdev_by_devno(read_dev_no); 1309 if (*dev == NULL) 1310 return -ENODEV; 1311 card = (*dev)->ml_priv; 1312 if (!card) 1313 return -ENODEV; 1314 QETH_CARD_TEXT(card, 2, "osnreg"); 1315 if ((assist_cb == NULL) || (data_cb == NULL)) 1316 return -EINVAL; 1317 card->osn_info.assist_cb = assist_cb; 1318 card->osn_info.data_cb = data_cb; 1319 return 0; 1320 } 1321 EXPORT_SYMBOL(qeth_osn_register); 1322 1323 void qeth_osn_deregister(struct net_device *dev) 1324 { 1325 struct qeth_card *card; 1326 1327 if (!dev) 1328 return; 1329 card = dev->ml_priv; 1330 if (!card) 1331 return; 1332 QETH_CARD_TEXT(card, 2, "osndereg"); 1333 card->osn_info.assist_cb = NULL; 1334 card->osn_info.data_cb = NULL; 1335 return; 1336 } 1337 EXPORT_SYMBOL(qeth_osn_deregister); 1338 1339 module_init(qeth_l2_init); 1340 module_exit(qeth_l2_exit); 1341 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); 1342 MODULE_DESCRIPTION("qeth layer 2 discipline"); 1343 MODULE_LICENSE("GPL"); 1344