1 /* 2 * FUJITSU Extended Socket Network Device driver 3 * Copyright (c) 2015 FUJITSU LIMITED 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms and conditions of the GNU General Public License, 7 * version 2, as published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 * You should have received a copy of the GNU General Public License along with 15 * this program; if not, see <http://www.gnu.org/licenses/>. 16 * 17 * The full GNU General Public License is included in this distribution in 18 * the file called "COPYING". 19 * 20 */ 21 22 #include <linux/module.h> 23 #include <linux/types.h> 24 #include <linux/nls.h> 25 #include <linux/platform_device.h> 26 #include <linux/netdevice.h> 27 #include <linux/interrupt.h> 28 29 #include "fjes.h" 30 31 #define MAJ 1 32 #define MIN 1 33 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) 34 #define DRV_NAME "fjes" 35 char fjes_driver_name[] = DRV_NAME; 36 char fjes_driver_version[] = DRV_VERSION; 37 static const char fjes_driver_string[] = 38 "FUJITSU Extended Socket Network Device Driver"; 39 static const char fjes_copyright[] = 40 "Copyright (c) 2015 FUJITSU LIMITED"; 41 42 MODULE_AUTHOR("Taku Izumi <izumi.taku@jp.fujitsu.com>"); 43 MODULE_DESCRIPTION("FUJITSU Extended Socket Network Device Driver"); 44 MODULE_LICENSE("GPL"); 45 MODULE_VERSION(DRV_VERSION); 46 47 static int fjes_request_irq(struct fjes_adapter *); 48 static void fjes_free_irq(struct fjes_adapter *); 49 50 static int fjes_open(struct net_device *); 51 static int fjes_close(struct net_device *); 52 static int fjes_setup_resources(struct fjes_adapter *); 53 static void fjes_free_resources(struct fjes_adapter *); 54 static netdev_tx_t fjes_xmit_frame(struct sk_buff *, struct net_device *); 55 static void fjes_raise_intr_rxdata_task(struct work_struct *); 56 static void fjes_tx_stall_task(struct work_struct *); 57 static void fjes_force_close_task(struct work_struct *); 58 static irqreturn_t fjes_intr(int, void*); 59 static struct rtnl_link_stats64 * 60 fjes_get_stats64(struct net_device *, struct rtnl_link_stats64 *); 61 static int fjes_change_mtu(struct net_device *, int); 62 static int fjes_vlan_rx_add_vid(struct net_device *, __be16 proto, u16); 63 static int fjes_vlan_rx_kill_vid(struct net_device *, __be16 proto, u16); 64 static void fjes_tx_retry(struct net_device *); 65 66 static int fjes_acpi_add(struct acpi_device *); 67 static int fjes_acpi_remove(struct acpi_device *); 68 static acpi_status fjes_get_acpi_resource(struct acpi_resource *, void*); 69 70 static int fjes_probe(struct platform_device *); 71 static int fjes_remove(struct platform_device *); 72 73 static int fjes_sw_init(struct fjes_adapter *); 74 static void fjes_netdev_setup(struct net_device *); 75 static void fjes_irq_watch_task(struct work_struct *); 76 static void fjes_watch_unshare_task(struct work_struct *); 77 static void fjes_rx_irq(struct fjes_adapter *, int); 78 static int fjes_poll(struct napi_struct *, int); 79 80 static const struct acpi_device_id fjes_acpi_ids[] = { 81 {"PNP0C02", 0}, 82 {"", 0}, 83 }; 84 MODULE_DEVICE_TABLE(acpi, fjes_acpi_ids); 85 86 static struct acpi_driver fjes_acpi_driver = { 87 .name = DRV_NAME, 88 .class = DRV_NAME, 89 .owner = THIS_MODULE, 90 .ids = fjes_acpi_ids, 91 .ops = { 92 .add = fjes_acpi_add, 93 .remove = fjes_acpi_remove, 94 }, 95 }; 96 97 static struct platform_driver fjes_driver = { 98 .driver = { 99 .name = DRV_NAME, 100 }, 101 .probe = fjes_probe, 102 .remove = fjes_remove, 103 }; 104 105 static struct resource fjes_resource[] = { 106 { 107 .flags = IORESOURCE_MEM, 108 .start = 0, 109 .end = 0, 110 }, 111 { 112 .flags = IORESOURCE_IRQ, 113 .start = 0, 114 .end = 0, 115 }, 116 }; 117 118 static int fjes_acpi_add(struct acpi_device *device) 119 { 120 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL}; 121 char str_buf[sizeof(FJES_ACPI_SYMBOL) + 1]; 122 struct platform_device *plat_dev; 123 union acpi_object *str; 124 acpi_status status; 125 int result; 126 127 status = acpi_evaluate_object(device->handle, "_STR", NULL, &buffer); 128 if (ACPI_FAILURE(status)) 129 return -ENODEV; 130 131 str = buffer.pointer; 132 result = utf16s_to_utf8s((wchar_t *)str->string.pointer, 133 str->string.length, UTF16_LITTLE_ENDIAN, 134 str_buf, sizeof(str_buf) - 1); 135 str_buf[result] = 0; 136 137 if (strncmp(FJES_ACPI_SYMBOL, str_buf, strlen(FJES_ACPI_SYMBOL)) != 0) { 138 kfree(buffer.pointer); 139 return -ENODEV; 140 } 141 kfree(buffer.pointer); 142 143 status = acpi_walk_resources(device->handle, METHOD_NAME__CRS, 144 fjes_get_acpi_resource, fjes_resource); 145 if (ACPI_FAILURE(status)) 146 return -ENODEV; 147 148 /* create platform_device */ 149 plat_dev = platform_device_register_simple(DRV_NAME, 0, fjes_resource, 150 ARRAY_SIZE(fjes_resource)); 151 device->driver_data = plat_dev; 152 153 return 0; 154 } 155 156 static int fjes_acpi_remove(struct acpi_device *device) 157 { 158 struct platform_device *plat_dev; 159 160 plat_dev = (struct platform_device *)acpi_driver_data(device); 161 platform_device_unregister(plat_dev); 162 163 return 0; 164 } 165 166 static acpi_status 167 fjes_get_acpi_resource(struct acpi_resource *acpi_res, void *data) 168 { 169 struct acpi_resource_address32 *addr; 170 struct acpi_resource_irq *irq; 171 struct resource *res = data; 172 173 switch (acpi_res->type) { 174 case ACPI_RESOURCE_TYPE_ADDRESS32: 175 addr = &acpi_res->data.address32; 176 res[0].start = addr->address.minimum; 177 res[0].end = addr->address.minimum + 178 addr->address.address_length - 1; 179 break; 180 181 case ACPI_RESOURCE_TYPE_IRQ: 182 irq = &acpi_res->data.irq; 183 if (irq->interrupt_count != 1) 184 return AE_ERROR; 185 res[1].start = irq->interrupts[0]; 186 res[1].end = irq->interrupts[0]; 187 break; 188 189 default: 190 break; 191 } 192 193 return AE_OK; 194 } 195 196 static int fjes_request_irq(struct fjes_adapter *adapter) 197 { 198 struct net_device *netdev = adapter->netdev; 199 int result = -1; 200 201 adapter->interrupt_watch_enable = true; 202 if (!delayed_work_pending(&adapter->interrupt_watch_task)) { 203 queue_delayed_work(adapter->control_wq, 204 &adapter->interrupt_watch_task, 205 FJES_IRQ_WATCH_DELAY); 206 } 207 208 if (!adapter->irq_registered) { 209 result = request_irq(adapter->hw.hw_res.irq, fjes_intr, 210 IRQF_SHARED, netdev->name, adapter); 211 if (result) 212 adapter->irq_registered = false; 213 else 214 adapter->irq_registered = true; 215 } 216 217 return result; 218 } 219 220 static void fjes_free_irq(struct fjes_adapter *adapter) 221 { 222 struct fjes_hw *hw = &adapter->hw; 223 224 adapter->interrupt_watch_enable = false; 225 cancel_delayed_work_sync(&adapter->interrupt_watch_task); 226 227 fjes_hw_set_irqmask(hw, REG_ICTL_MASK_ALL, true); 228 229 if (adapter->irq_registered) { 230 free_irq(adapter->hw.hw_res.irq, adapter); 231 adapter->irq_registered = false; 232 } 233 } 234 235 static const struct net_device_ops fjes_netdev_ops = { 236 .ndo_open = fjes_open, 237 .ndo_stop = fjes_close, 238 .ndo_start_xmit = fjes_xmit_frame, 239 .ndo_get_stats64 = fjes_get_stats64, 240 .ndo_change_mtu = fjes_change_mtu, 241 .ndo_tx_timeout = fjes_tx_retry, 242 .ndo_vlan_rx_add_vid = fjes_vlan_rx_add_vid, 243 .ndo_vlan_rx_kill_vid = fjes_vlan_rx_kill_vid, 244 }; 245 246 /* fjes_open - Called when a network interface is made active */ 247 static int fjes_open(struct net_device *netdev) 248 { 249 struct fjes_adapter *adapter = netdev_priv(netdev); 250 struct fjes_hw *hw = &adapter->hw; 251 int result; 252 253 if (adapter->open_guard) 254 return -ENXIO; 255 256 result = fjes_setup_resources(adapter); 257 if (result) 258 goto err_setup_res; 259 260 hw->txrx_stop_req_bit = 0; 261 hw->epstop_req_bit = 0; 262 263 napi_enable(&adapter->napi); 264 265 fjes_hw_capture_interrupt_status(hw); 266 267 result = fjes_request_irq(adapter); 268 if (result) 269 goto err_req_irq; 270 271 fjes_hw_set_irqmask(hw, REG_ICTL_MASK_ALL, false); 272 273 netif_tx_start_all_queues(netdev); 274 netif_carrier_on(netdev); 275 276 return 0; 277 278 err_req_irq: 279 fjes_free_irq(adapter); 280 napi_disable(&adapter->napi); 281 282 err_setup_res: 283 fjes_free_resources(adapter); 284 return result; 285 } 286 287 /* fjes_close - Disables a network interface */ 288 static int fjes_close(struct net_device *netdev) 289 { 290 struct fjes_adapter *adapter = netdev_priv(netdev); 291 struct fjes_hw *hw = &adapter->hw; 292 unsigned long flags; 293 int epidx; 294 295 netif_tx_stop_all_queues(netdev); 296 netif_carrier_off(netdev); 297 298 fjes_hw_raise_epstop(hw); 299 300 napi_disable(&adapter->napi); 301 302 spin_lock_irqsave(&hw->rx_status_lock, flags); 303 for (epidx = 0; epidx < hw->max_epid; epidx++) { 304 if (epidx == hw->my_epid) 305 continue; 306 307 if (fjes_hw_get_partner_ep_status(hw, epidx) == 308 EP_PARTNER_SHARED) 309 adapter->hw.ep_shm_info[epidx] 310 .tx.info->v1i.rx_status &= 311 ~FJES_RX_POLL_WORK; 312 } 313 spin_unlock_irqrestore(&hw->rx_status_lock, flags); 314 315 fjes_free_irq(adapter); 316 317 cancel_delayed_work_sync(&adapter->interrupt_watch_task); 318 cancel_work_sync(&adapter->unshare_watch_task); 319 adapter->unshare_watch_bitmask = 0; 320 cancel_work_sync(&adapter->raise_intr_rxdata_task); 321 cancel_work_sync(&adapter->tx_stall_task); 322 323 cancel_work_sync(&hw->update_zone_task); 324 cancel_work_sync(&hw->epstop_task); 325 326 fjes_hw_wait_epstop(hw); 327 328 fjes_free_resources(adapter); 329 330 return 0; 331 } 332 333 static int fjes_setup_resources(struct fjes_adapter *adapter) 334 { 335 struct net_device *netdev = adapter->netdev; 336 struct ep_share_mem_info *buf_pair; 337 struct fjes_hw *hw = &adapter->hw; 338 unsigned long flags; 339 int result; 340 int epidx; 341 342 mutex_lock(&hw->hw_info.lock); 343 result = fjes_hw_request_info(hw); 344 switch (result) { 345 case 0: 346 for (epidx = 0; epidx < hw->max_epid; epidx++) { 347 hw->ep_shm_info[epidx].es_status = 348 hw->hw_info.res_buf->info.info[epidx].es_status; 349 hw->ep_shm_info[epidx].zone = 350 hw->hw_info.res_buf->info.info[epidx].zone; 351 } 352 break; 353 default: 354 case -ENOMSG: 355 case -EBUSY: 356 adapter->force_reset = true; 357 358 mutex_unlock(&hw->hw_info.lock); 359 return result; 360 } 361 mutex_unlock(&hw->hw_info.lock); 362 363 for (epidx = 0; epidx < (hw->max_epid); epidx++) { 364 if ((epidx != hw->my_epid) && 365 (hw->ep_shm_info[epidx].es_status == 366 FJES_ZONING_STATUS_ENABLE)) { 367 fjes_hw_raise_interrupt(hw, epidx, 368 REG_ICTL_MASK_INFO_UPDATE); 369 } 370 } 371 372 msleep(FJES_OPEN_ZONE_UPDATE_WAIT * hw->max_epid); 373 374 for (epidx = 0; epidx < (hw->max_epid); epidx++) { 375 if (epidx == hw->my_epid) 376 continue; 377 378 buf_pair = &hw->ep_shm_info[epidx]; 379 380 spin_lock_irqsave(&hw->rx_status_lock, flags); 381 fjes_hw_setup_epbuf(&buf_pair->tx, netdev->dev_addr, 382 netdev->mtu); 383 spin_unlock_irqrestore(&hw->rx_status_lock, flags); 384 385 if (fjes_hw_epid_is_same_zone(hw, epidx)) { 386 mutex_lock(&hw->hw_info.lock); 387 result = 388 fjes_hw_register_buff_addr(hw, epidx, buf_pair); 389 mutex_unlock(&hw->hw_info.lock); 390 391 switch (result) { 392 case 0: 393 break; 394 case -ENOMSG: 395 case -EBUSY: 396 default: 397 adapter->force_reset = true; 398 return result; 399 } 400 } 401 } 402 403 return 0; 404 } 405 406 static void fjes_free_resources(struct fjes_adapter *adapter) 407 { 408 struct net_device *netdev = adapter->netdev; 409 struct fjes_device_command_param param; 410 struct ep_share_mem_info *buf_pair; 411 struct fjes_hw *hw = &adapter->hw; 412 bool reset_flag = false; 413 unsigned long flags; 414 int result; 415 int epidx; 416 417 for (epidx = 0; epidx < hw->max_epid; epidx++) { 418 if (epidx == hw->my_epid) 419 continue; 420 421 mutex_lock(&hw->hw_info.lock); 422 result = fjes_hw_unregister_buff_addr(hw, epidx); 423 mutex_unlock(&hw->hw_info.lock); 424 425 if (result) 426 reset_flag = true; 427 428 buf_pair = &hw->ep_shm_info[epidx]; 429 430 spin_lock_irqsave(&hw->rx_status_lock, flags); 431 fjes_hw_setup_epbuf(&buf_pair->tx, 432 netdev->dev_addr, netdev->mtu); 433 spin_unlock_irqrestore(&hw->rx_status_lock, flags); 434 435 clear_bit(epidx, &hw->txrx_stop_req_bit); 436 } 437 438 if (reset_flag || adapter->force_reset) { 439 result = fjes_hw_reset(hw); 440 441 adapter->force_reset = false; 442 443 if (result) 444 adapter->open_guard = true; 445 446 hw->hw_info.buffer_share_bit = 0; 447 448 memset((void *)¶m, 0, sizeof(param)); 449 450 param.req_len = hw->hw_info.req_buf_size; 451 param.req_start = __pa(hw->hw_info.req_buf); 452 param.res_len = hw->hw_info.res_buf_size; 453 param.res_start = __pa(hw->hw_info.res_buf); 454 param.share_start = __pa(hw->hw_info.share->ep_status); 455 456 fjes_hw_init_command_registers(hw, ¶m); 457 } 458 } 459 460 static void fjes_tx_stall_task(struct work_struct *work) 461 { 462 struct fjes_adapter *adapter = container_of(work, 463 struct fjes_adapter, tx_stall_task); 464 struct net_device *netdev = adapter->netdev; 465 struct fjes_hw *hw = &adapter->hw; 466 int all_queue_available, sendable; 467 enum ep_partner_status pstatus; 468 int max_epid, my_epid, epid; 469 union ep_buffer_info *info; 470 int i; 471 472 if (((long)jiffies - 473 dev_trans_start(netdev)) > FJES_TX_TX_STALL_TIMEOUT) { 474 netif_wake_queue(netdev); 475 return; 476 } 477 478 my_epid = hw->my_epid; 479 max_epid = hw->max_epid; 480 481 for (i = 0; i < 5; i++) { 482 all_queue_available = 1; 483 484 for (epid = 0; epid < max_epid; epid++) { 485 if (my_epid == epid) 486 continue; 487 488 pstatus = fjes_hw_get_partner_ep_status(hw, epid); 489 sendable = (pstatus == EP_PARTNER_SHARED); 490 if (!sendable) 491 continue; 492 493 info = adapter->hw.ep_shm_info[epid].tx.info; 494 495 if (!(info->v1i.rx_status & FJES_RX_MTU_CHANGING_DONE)) 496 return; 497 498 if (EP_RING_FULL(info->v1i.head, info->v1i.tail, 499 info->v1i.count_max)) { 500 all_queue_available = 0; 501 break; 502 } 503 } 504 505 if (all_queue_available) { 506 netif_wake_queue(netdev); 507 return; 508 } 509 } 510 511 usleep_range(50, 100); 512 513 queue_work(adapter->txrx_wq, &adapter->tx_stall_task); 514 } 515 516 static void fjes_force_close_task(struct work_struct *work) 517 { 518 struct fjes_adapter *adapter = container_of(work, 519 struct fjes_adapter, force_close_task); 520 struct net_device *netdev = adapter->netdev; 521 522 rtnl_lock(); 523 dev_close(netdev); 524 rtnl_unlock(); 525 } 526 527 static void fjes_raise_intr_rxdata_task(struct work_struct *work) 528 { 529 struct fjes_adapter *adapter = container_of(work, 530 struct fjes_adapter, raise_intr_rxdata_task); 531 struct fjes_hw *hw = &adapter->hw; 532 enum ep_partner_status pstatus; 533 int max_epid, my_epid, epid; 534 535 my_epid = hw->my_epid; 536 max_epid = hw->max_epid; 537 538 for (epid = 0; epid < max_epid; epid++) 539 hw->ep_shm_info[epid].tx_status_work = 0; 540 541 for (epid = 0; epid < max_epid; epid++) { 542 if (epid == my_epid) 543 continue; 544 545 pstatus = fjes_hw_get_partner_ep_status(hw, epid); 546 if (pstatus == EP_PARTNER_SHARED) { 547 hw->ep_shm_info[epid].tx_status_work = 548 hw->ep_shm_info[epid].tx.info->v1i.tx_status; 549 550 if (hw->ep_shm_info[epid].tx_status_work == 551 FJES_TX_DELAY_SEND_PENDING) { 552 hw->ep_shm_info[epid].tx.info->v1i.tx_status = 553 FJES_TX_DELAY_SEND_NONE; 554 } 555 } 556 } 557 558 for (epid = 0; epid < max_epid; epid++) { 559 if (epid == my_epid) 560 continue; 561 562 pstatus = fjes_hw_get_partner_ep_status(hw, epid); 563 if ((hw->ep_shm_info[epid].tx_status_work == 564 FJES_TX_DELAY_SEND_PENDING) && 565 (pstatus == EP_PARTNER_SHARED) && 566 !(hw->ep_shm_info[epid].rx.info->v1i.rx_status & 567 FJES_RX_POLL_WORK)) { 568 fjes_hw_raise_interrupt(hw, epid, 569 REG_ICTL_MASK_RX_DATA); 570 } 571 } 572 573 usleep_range(500, 1000); 574 } 575 576 static int fjes_tx_send(struct fjes_adapter *adapter, int dest, 577 void *data, size_t len) 578 { 579 int retval; 580 581 retval = fjes_hw_epbuf_tx_pkt_send(&adapter->hw.ep_shm_info[dest].tx, 582 data, len); 583 if (retval) 584 return retval; 585 586 adapter->hw.ep_shm_info[dest].tx.info->v1i.tx_status = 587 FJES_TX_DELAY_SEND_PENDING; 588 if (!work_pending(&adapter->raise_intr_rxdata_task)) 589 queue_work(adapter->txrx_wq, 590 &adapter->raise_intr_rxdata_task); 591 592 retval = 0; 593 return retval; 594 } 595 596 static netdev_tx_t 597 fjes_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 598 { 599 struct fjes_adapter *adapter = netdev_priv(netdev); 600 struct fjes_hw *hw = &adapter->hw; 601 602 int max_epid, my_epid, dest_epid; 603 enum ep_partner_status pstatus; 604 struct netdev_queue *cur_queue; 605 char shortpkt[VLAN_ETH_HLEN]; 606 bool is_multi, vlan; 607 struct ethhdr *eth; 608 u16 queue_no = 0; 609 u16 vlan_id = 0; 610 netdev_tx_t ret; 611 char *data; 612 int len; 613 614 ret = NETDEV_TX_OK; 615 is_multi = false; 616 cur_queue = netdev_get_tx_queue(netdev, queue_no); 617 618 eth = (struct ethhdr *)skb->data; 619 my_epid = hw->my_epid; 620 621 vlan = (vlan_get_tag(skb, &vlan_id) == 0) ? true : false; 622 623 data = skb->data; 624 len = skb->len; 625 626 if (is_multicast_ether_addr(eth->h_dest)) { 627 dest_epid = 0; 628 max_epid = hw->max_epid; 629 is_multi = true; 630 } else if (is_local_ether_addr(eth->h_dest)) { 631 dest_epid = eth->h_dest[ETH_ALEN - 1]; 632 max_epid = dest_epid + 1; 633 634 if ((eth->h_dest[0] == 0x02) && 635 (0x00 == (eth->h_dest[1] | eth->h_dest[2] | 636 eth->h_dest[3] | eth->h_dest[4])) && 637 (dest_epid < hw->max_epid)) { 638 ; 639 } else { 640 dest_epid = 0; 641 max_epid = 0; 642 ret = NETDEV_TX_OK; 643 644 adapter->stats64.tx_packets += 1; 645 hw->ep_shm_info[my_epid].net_stats.tx_packets += 1; 646 adapter->stats64.tx_bytes += len; 647 hw->ep_shm_info[my_epid].net_stats.tx_bytes += len; 648 } 649 } else { 650 dest_epid = 0; 651 max_epid = 0; 652 ret = NETDEV_TX_OK; 653 654 adapter->stats64.tx_packets += 1; 655 hw->ep_shm_info[my_epid].net_stats.tx_packets += 1; 656 adapter->stats64.tx_bytes += len; 657 hw->ep_shm_info[my_epid].net_stats.tx_bytes += len; 658 } 659 660 for (; dest_epid < max_epid; dest_epid++) { 661 if (my_epid == dest_epid) 662 continue; 663 664 pstatus = fjes_hw_get_partner_ep_status(hw, dest_epid); 665 if (pstatus != EP_PARTNER_SHARED) { 666 ret = NETDEV_TX_OK; 667 } else if (!fjes_hw_check_epbuf_version( 668 &adapter->hw.ep_shm_info[dest_epid].rx, 0)) { 669 /* version is NOT 0 */ 670 adapter->stats64.tx_carrier_errors += 1; 671 hw->ep_shm_info[dest_epid].net_stats 672 .tx_carrier_errors += 1; 673 674 ret = NETDEV_TX_OK; 675 } else if (!fjes_hw_check_mtu( 676 &adapter->hw.ep_shm_info[dest_epid].rx, 677 netdev->mtu)) { 678 adapter->stats64.tx_dropped += 1; 679 hw->ep_shm_info[dest_epid].net_stats.tx_dropped += 1; 680 adapter->stats64.tx_errors += 1; 681 hw->ep_shm_info[dest_epid].net_stats.tx_errors += 1; 682 683 ret = NETDEV_TX_OK; 684 } else if (vlan && 685 !fjes_hw_check_vlan_id( 686 &adapter->hw.ep_shm_info[dest_epid].rx, 687 vlan_id)) { 688 ret = NETDEV_TX_OK; 689 } else { 690 if (len < VLAN_ETH_HLEN) { 691 memset(shortpkt, 0, VLAN_ETH_HLEN); 692 memcpy(shortpkt, skb->data, skb->len); 693 len = VLAN_ETH_HLEN; 694 data = shortpkt; 695 } 696 697 if (adapter->tx_retry_count == 0) { 698 adapter->tx_start_jiffies = jiffies; 699 adapter->tx_retry_count = 1; 700 } else { 701 adapter->tx_retry_count++; 702 } 703 704 if (fjes_tx_send(adapter, dest_epid, data, len)) { 705 if (is_multi) { 706 ret = NETDEV_TX_OK; 707 } else if ( 708 ((long)jiffies - 709 (long)adapter->tx_start_jiffies) >= 710 FJES_TX_RETRY_TIMEOUT) { 711 adapter->stats64.tx_fifo_errors += 1; 712 hw->ep_shm_info[dest_epid].net_stats 713 .tx_fifo_errors += 1; 714 adapter->stats64.tx_errors += 1; 715 hw->ep_shm_info[dest_epid].net_stats 716 .tx_errors += 1; 717 718 ret = NETDEV_TX_OK; 719 } else { 720 netif_trans_update(netdev); 721 netif_tx_stop_queue(cur_queue); 722 723 if (!work_pending(&adapter->tx_stall_task)) 724 queue_work(adapter->txrx_wq, 725 &adapter->tx_stall_task); 726 727 ret = NETDEV_TX_BUSY; 728 } 729 } else { 730 if (!is_multi) { 731 adapter->stats64.tx_packets += 1; 732 hw->ep_shm_info[dest_epid].net_stats 733 .tx_packets += 1; 734 adapter->stats64.tx_bytes += len; 735 hw->ep_shm_info[dest_epid].net_stats 736 .tx_bytes += len; 737 } 738 739 adapter->tx_retry_count = 0; 740 ret = NETDEV_TX_OK; 741 } 742 } 743 } 744 745 if (ret == NETDEV_TX_OK) { 746 dev_kfree_skb(skb); 747 if (is_multi) { 748 adapter->stats64.tx_packets += 1; 749 hw->ep_shm_info[my_epid].net_stats.tx_packets += 1; 750 adapter->stats64.tx_bytes += 1; 751 hw->ep_shm_info[my_epid].net_stats.tx_bytes += len; 752 } 753 } 754 755 return ret; 756 } 757 758 static void fjes_tx_retry(struct net_device *netdev) 759 { 760 struct netdev_queue *queue = netdev_get_tx_queue(netdev, 0); 761 762 netif_tx_wake_queue(queue); 763 } 764 765 static struct rtnl_link_stats64 * 766 fjes_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) 767 { 768 struct fjes_adapter *adapter = netdev_priv(netdev); 769 770 memcpy(stats, &adapter->stats64, sizeof(struct rtnl_link_stats64)); 771 772 return stats; 773 } 774 775 static int fjes_change_mtu(struct net_device *netdev, int new_mtu) 776 { 777 struct fjes_adapter *adapter = netdev_priv(netdev); 778 bool running = netif_running(netdev); 779 struct fjes_hw *hw = &adapter->hw; 780 unsigned long flags; 781 int ret = -EINVAL; 782 int idx, epidx; 783 784 for (idx = 0; fjes_support_mtu[idx] != 0; idx++) { 785 if (new_mtu <= fjes_support_mtu[idx]) { 786 new_mtu = fjes_support_mtu[idx]; 787 if (new_mtu == netdev->mtu) 788 return 0; 789 790 ret = 0; 791 break; 792 } 793 } 794 795 if (ret) 796 return ret; 797 798 if (running) { 799 spin_lock_irqsave(&hw->rx_status_lock, flags); 800 for (epidx = 0; epidx < hw->max_epid; epidx++) { 801 if (epidx == hw->my_epid) 802 continue; 803 hw->ep_shm_info[epidx].tx.info->v1i.rx_status &= 804 ~FJES_RX_MTU_CHANGING_DONE; 805 } 806 spin_unlock_irqrestore(&hw->rx_status_lock, flags); 807 808 netif_tx_stop_all_queues(netdev); 809 netif_carrier_off(netdev); 810 cancel_work_sync(&adapter->tx_stall_task); 811 napi_disable(&adapter->napi); 812 813 msleep(1000); 814 815 netif_tx_stop_all_queues(netdev); 816 } 817 818 netdev->mtu = new_mtu; 819 820 if (running) { 821 for (epidx = 0; epidx < hw->max_epid; epidx++) { 822 if (epidx == hw->my_epid) 823 continue; 824 825 spin_lock_irqsave(&hw->rx_status_lock, flags); 826 fjes_hw_setup_epbuf(&hw->ep_shm_info[epidx].tx, 827 netdev->dev_addr, 828 netdev->mtu); 829 830 hw->ep_shm_info[epidx].tx.info->v1i.rx_status |= 831 FJES_RX_MTU_CHANGING_DONE; 832 spin_unlock_irqrestore(&hw->rx_status_lock, flags); 833 } 834 835 netif_tx_wake_all_queues(netdev); 836 netif_carrier_on(netdev); 837 napi_enable(&adapter->napi); 838 napi_schedule(&adapter->napi); 839 } 840 841 return ret; 842 } 843 844 static int fjes_vlan_rx_add_vid(struct net_device *netdev, 845 __be16 proto, u16 vid) 846 { 847 struct fjes_adapter *adapter = netdev_priv(netdev); 848 bool ret = true; 849 int epid; 850 851 for (epid = 0; epid < adapter->hw.max_epid; epid++) { 852 if (epid == adapter->hw.my_epid) 853 continue; 854 855 if (!fjes_hw_check_vlan_id( 856 &adapter->hw.ep_shm_info[epid].tx, vid)) 857 ret = fjes_hw_set_vlan_id( 858 &adapter->hw.ep_shm_info[epid].tx, vid); 859 } 860 861 return ret ? 0 : -ENOSPC; 862 } 863 864 static int fjes_vlan_rx_kill_vid(struct net_device *netdev, 865 __be16 proto, u16 vid) 866 { 867 struct fjes_adapter *adapter = netdev_priv(netdev); 868 int epid; 869 870 for (epid = 0; epid < adapter->hw.max_epid; epid++) { 871 if (epid == adapter->hw.my_epid) 872 continue; 873 874 fjes_hw_del_vlan_id(&adapter->hw.ep_shm_info[epid].tx, vid); 875 } 876 877 return 0; 878 } 879 880 static void fjes_txrx_stop_req_irq(struct fjes_adapter *adapter, 881 int src_epid) 882 { 883 struct fjes_hw *hw = &adapter->hw; 884 enum ep_partner_status status; 885 unsigned long flags; 886 887 status = fjes_hw_get_partner_ep_status(hw, src_epid); 888 switch (status) { 889 case EP_PARTNER_UNSHARE: 890 case EP_PARTNER_COMPLETE: 891 default: 892 break; 893 case EP_PARTNER_WAITING: 894 if (src_epid < hw->my_epid) { 895 spin_lock_irqsave(&hw->rx_status_lock, flags); 896 hw->ep_shm_info[src_epid].tx.info->v1i.rx_status |= 897 FJES_RX_STOP_REQ_DONE; 898 spin_unlock_irqrestore(&hw->rx_status_lock, flags); 899 900 clear_bit(src_epid, &hw->txrx_stop_req_bit); 901 set_bit(src_epid, &adapter->unshare_watch_bitmask); 902 903 if (!work_pending(&adapter->unshare_watch_task)) 904 queue_work(adapter->control_wq, 905 &adapter->unshare_watch_task); 906 } 907 break; 908 case EP_PARTNER_SHARED: 909 if (hw->ep_shm_info[src_epid].rx.info->v1i.rx_status & 910 FJES_RX_STOP_REQ_REQUEST) { 911 set_bit(src_epid, &hw->epstop_req_bit); 912 if (!work_pending(&hw->epstop_task)) 913 queue_work(adapter->control_wq, 914 &hw->epstop_task); 915 } 916 break; 917 } 918 } 919 920 static void fjes_stop_req_irq(struct fjes_adapter *adapter, int src_epid) 921 { 922 struct fjes_hw *hw = &adapter->hw; 923 enum ep_partner_status status; 924 unsigned long flags; 925 926 set_bit(src_epid, &hw->hw_info.buffer_unshare_reserve_bit); 927 928 status = fjes_hw_get_partner_ep_status(hw, src_epid); 929 switch (status) { 930 case EP_PARTNER_WAITING: 931 spin_lock_irqsave(&hw->rx_status_lock, flags); 932 hw->ep_shm_info[src_epid].tx.info->v1i.rx_status |= 933 FJES_RX_STOP_REQ_DONE; 934 spin_unlock_irqrestore(&hw->rx_status_lock, flags); 935 clear_bit(src_epid, &hw->txrx_stop_req_bit); 936 /* fall through */ 937 case EP_PARTNER_UNSHARE: 938 case EP_PARTNER_COMPLETE: 939 default: 940 set_bit(src_epid, &adapter->unshare_watch_bitmask); 941 if (!work_pending(&adapter->unshare_watch_task)) 942 queue_work(adapter->control_wq, 943 &adapter->unshare_watch_task); 944 break; 945 case EP_PARTNER_SHARED: 946 set_bit(src_epid, &hw->epstop_req_bit); 947 948 if (!work_pending(&hw->epstop_task)) 949 queue_work(adapter->control_wq, &hw->epstop_task); 950 break; 951 } 952 } 953 954 static void fjes_update_zone_irq(struct fjes_adapter *adapter, 955 int src_epid) 956 { 957 struct fjes_hw *hw = &adapter->hw; 958 959 if (!work_pending(&hw->update_zone_task)) 960 queue_work(adapter->control_wq, &hw->update_zone_task); 961 } 962 963 static irqreturn_t fjes_intr(int irq, void *data) 964 { 965 struct fjes_adapter *adapter = data; 966 struct fjes_hw *hw = &adapter->hw; 967 irqreturn_t ret; 968 u32 icr; 969 970 icr = fjes_hw_capture_interrupt_status(hw); 971 972 if (icr & REG_IS_MASK_IS_ASSERT) { 973 if (icr & REG_ICTL_MASK_RX_DATA) 974 fjes_rx_irq(adapter, icr & REG_IS_MASK_EPID); 975 976 if (icr & REG_ICTL_MASK_DEV_STOP_REQ) 977 fjes_stop_req_irq(adapter, icr & REG_IS_MASK_EPID); 978 979 if (icr & REG_ICTL_MASK_TXRX_STOP_REQ) 980 fjes_txrx_stop_req_irq(adapter, icr & REG_IS_MASK_EPID); 981 982 if (icr & REG_ICTL_MASK_TXRX_STOP_DONE) 983 fjes_hw_set_irqmask(hw, 984 REG_ICTL_MASK_TXRX_STOP_DONE, true); 985 986 if (icr & REG_ICTL_MASK_INFO_UPDATE) 987 fjes_update_zone_irq(adapter, icr & REG_IS_MASK_EPID); 988 989 ret = IRQ_HANDLED; 990 } else { 991 ret = IRQ_NONE; 992 } 993 994 return ret; 995 } 996 997 static int fjes_rxframe_search_exist(struct fjes_adapter *adapter, 998 int start_epid) 999 { 1000 struct fjes_hw *hw = &adapter->hw; 1001 enum ep_partner_status pstatus; 1002 int max_epid, cur_epid; 1003 int i; 1004 1005 max_epid = hw->max_epid; 1006 start_epid = (start_epid + 1 + max_epid) % max_epid; 1007 1008 for (i = 0; i < max_epid; i++) { 1009 cur_epid = (start_epid + i) % max_epid; 1010 if (cur_epid == hw->my_epid) 1011 continue; 1012 1013 pstatus = fjes_hw_get_partner_ep_status(hw, cur_epid); 1014 if (pstatus == EP_PARTNER_SHARED) { 1015 if (!fjes_hw_epbuf_rx_is_empty( 1016 &hw->ep_shm_info[cur_epid].rx)) 1017 return cur_epid; 1018 } 1019 } 1020 return -1; 1021 } 1022 1023 static void *fjes_rxframe_get(struct fjes_adapter *adapter, size_t *psize, 1024 int *cur_epid) 1025 { 1026 void *frame; 1027 1028 *cur_epid = fjes_rxframe_search_exist(adapter, *cur_epid); 1029 if (*cur_epid < 0) 1030 return NULL; 1031 1032 frame = 1033 fjes_hw_epbuf_rx_curpkt_get_addr( 1034 &adapter->hw.ep_shm_info[*cur_epid].rx, psize); 1035 1036 return frame; 1037 } 1038 1039 static void fjes_rxframe_release(struct fjes_adapter *adapter, int cur_epid) 1040 { 1041 fjes_hw_epbuf_rx_curpkt_drop(&adapter->hw.ep_shm_info[cur_epid].rx); 1042 } 1043 1044 static void fjes_rx_irq(struct fjes_adapter *adapter, int src_epid) 1045 { 1046 struct fjes_hw *hw = &adapter->hw; 1047 1048 fjes_hw_set_irqmask(hw, REG_ICTL_MASK_RX_DATA, true); 1049 1050 adapter->unset_rx_last = true; 1051 napi_schedule(&adapter->napi); 1052 } 1053 1054 static int fjes_poll(struct napi_struct *napi, int budget) 1055 { 1056 struct fjes_adapter *adapter = 1057 container_of(napi, struct fjes_adapter, napi); 1058 struct net_device *netdev = napi->dev; 1059 struct fjes_hw *hw = &adapter->hw; 1060 struct sk_buff *skb; 1061 int work_done = 0; 1062 int cur_epid = 0; 1063 int epidx; 1064 size_t frame_len; 1065 void *frame; 1066 1067 spin_lock(&hw->rx_status_lock); 1068 for (epidx = 0; epidx < hw->max_epid; epidx++) { 1069 if (epidx == hw->my_epid) 1070 continue; 1071 1072 if (fjes_hw_get_partner_ep_status(hw, epidx) == 1073 EP_PARTNER_SHARED) 1074 adapter->hw.ep_shm_info[epidx] 1075 .tx.info->v1i.rx_status |= FJES_RX_POLL_WORK; 1076 } 1077 spin_unlock(&hw->rx_status_lock); 1078 1079 while (work_done < budget) { 1080 prefetch(&adapter->hw); 1081 frame = fjes_rxframe_get(adapter, &frame_len, &cur_epid); 1082 1083 if (frame) { 1084 skb = napi_alloc_skb(napi, frame_len); 1085 if (!skb) { 1086 adapter->stats64.rx_dropped += 1; 1087 hw->ep_shm_info[cur_epid].net_stats 1088 .rx_dropped += 1; 1089 adapter->stats64.rx_errors += 1; 1090 hw->ep_shm_info[cur_epid].net_stats 1091 .rx_errors += 1; 1092 } else { 1093 memcpy(skb_put(skb, frame_len), 1094 frame, frame_len); 1095 skb->protocol = eth_type_trans(skb, netdev); 1096 skb->ip_summed = CHECKSUM_UNNECESSARY; 1097 1098 netif_receive_skb(skb); 1099 1100 work_done++; 1101 1102 adapter->stats64.rx_packets += 1; 1103 hw->ep_shm_info[cur_epid].net_stats 1104 .rx_packets += 1; 1105 adapter->stats64.rx_bytes += frame_len; 1106 hw->ep_shm_info[cur_epid].net_stats 1107 .rx_bytes += frame_len; 1108 1109 if (is_multicast_ether_addr( 1110 ((struct ethhdr *)frame)->h_dest)) { 1111 adapter->stats64.multicast += 1; 1112 hw->ep_shm_info[cur_epid].net_stats 1113 .multicast += 1; 1114 } 1115 } 1116 1117 fjes_rxframe_release(adapter, cur_epid); 1118 adapter->unset_rx_last = true; 1119 } else { 1120 break; 1121 } 1122 } 1123 1124 if (work_done < budget) { 1125 napi_complete(napi); 1126 1127 if (adapter->unset_rx_last) { 1128 adapter->rx_last_jiffies = jiffies; 1129 adapter->unset_rx_last = false; 1130 } 1131 1132 if (((long)jiffies - (long)adapter->rx_last_jiffies) < 3) { 1133 napi_reschedule(napi); 1134 } else { 1135 spin_lock(&hw->rx_status_lock); 1136 for (epidx = 0; epidx < hw->max_epid; epidx++) { 1137 if (epidx == hw->my_epid) 1138 continue; 1139 if (fjes_hw_get_partner_ep_status(hw, epidx) == 1140 EP_PARTNER_SHARED) 1141 adapter->hw.ep_shm_info[epidx].tx 1142 .info->v1i.rx_status &= 1143 ~FJES_RX_POLL_WORK; 1144 } 1145 spin_unlock(&hw->rx_status_lock); 1146 1147 fjes_hw_set_irqmask(hw, REG_ICTL_MASK_RX_DATA, false); 1148 } 1149 } 1150 1151 return work_done; 1152 } 1153 1154 /* fjes_probe - Device Initialization Routine */ 1155 static int fjes_probe(struct platform_device *plat_dev) 1156 { 1157 struct fjes_adapter *adapter; 1158 struct net_device *netdev; 1159 struct resource *res; 1160 struct fjes_hw *hw; 1161 int err; 1162 1163 err = -ENOMEM; 1164 netdev = alloc_netdev_mq(sizeof(struct fjes_adapter), "es%d", 1165 NET_NAME_UNKNOWN, fjes_netdev_setup, 1166 FJES_MAX_QUEUES); 1167 1168 if (!netdev) 1169 goto err_out; 1170 1171 SET_NETDEV_DEV(netdev, &plat_dev->dev); 1172 1173 dev_set_drvdata(&plat_dev->dev, netdev); 1174 adapter = netdev_priv(netdev); 1175 adapter->netdev = netdev; 1176 adapter->plat_dev = plat_dev; 1177 hw = &adapter->hw; 1178 hw->back = adapter; 1179 1180 /* setup the private structure */ 1181 err = fjes_sw_init(adapter); 1182 if (err) 1183 goto err_free_netdev; 1184 1185 INIT_WORK(&adapter->force_close_task, fjes_force_close_task); 1186 adapter->force_reset = false; 1187 adapter->open_guard = false; 1188 1189 adapter->txrx_wq = alloc_workqueue(DRV_NAME "/txrx", WQ_MEM_RECLAIM, 0); 1190 adapter->control_wq = alloc_workqueue(DRV_NAME "/control", 1191 WQ_MEM_RECLAIM, 0); 1192 1193 INIT_WORK(&adapter->tx_stall_task, fjes_tx_stall_task); 1194 INIT_WORK(&adapter->raise_intr_rxdata_task, 1195 fjes_raise_intr_rxdata_task); 1196 INIT_WORK(&adapter->unshare_watch_task, fjes_watch_unshare_task); 1197 adapter->unshare_watch_bitmask = 0; 1198 1199 INIT_DELAYED_WORK(&adapter->interrupt_watch_task, fjes_irq_watch_task); 1200 adapter->interrupt_watch_enable = false; 1201 1202 res = platform_get_resource(plat_dev, IORESOURCE_MEM, 0); 1203 hw->hw_res.start = res->start; 1204 hw->hw_res.size = resource_size(res); 1205 hw->hw_res.irq = platform_get_irq(plat_dev, 0); 1206 err = fjes_hw_init(&adapter->hw); 1207 if (err) 1208 goto err_free_netdev; 1209 1210 /* setup MAC address (02:00:00:00:00:[epid])*/ 1211 netdev->dev_addr[0] = 2; 1212 netdev->dev_addr[1] = 0; 1213 netdev->dev_addr[2] = 0; 1214 netdev->dev_addr[3] = 0; 1215 netdev->dev_addr[4] = 0; 1216 netdev->dev_addr[5] = hw->my_epid; /* EPID */ 1217 1218 err = register_netdev(netdev); 1219 if (err) 1220 goto err_hw_exit; 1221 1222 netif_carrier_off(netdev); 1223 1224 return 0; 1225 1226 err_hw_exit: 1227 fjes_hw_exit(&adapter->hw); 1228 err_free_netdev: 1229 free_netdev(netdev); 1230 err_out: 1231 return err; 1232 } 1233 1234 /* fjes_remove - Device Removal Routine */ 1235 static int fjes_remove(struct platform_device *plat_dev) 1236 { 1237 struct net_device *netdev = dev_get_drvdata(&plat_dev->dev); 1238 struct fjes_adapter *adapter = netdev_priv(netdev); 1239 struct fjes_hw *hw = &adapter->hw; 1240 1241 cancel_delayed_work_sync(&adapter->interrupt_watch_task); 1242 cancel_work_sync(&adapter->unshare_watch_task); 1243 cancel_work_sync(&adapter->raise_intr_rxdata_task); 1244 cancel_work_sync(&adapter->tx_stall_task); 1245 if (adapter->control_wq) 1246 destroy_workqueue(adapter->control_wq); 1247 if (adapter->txrx_wq) 1248 destroy_workqueue(adapter->txrx_wq); 1249 1250 unregister_netdev(netdev); 1251 1252 fjes_hw_exit(hw); 1253 1254 netif_napi_del(&adapter->napi); 1255 1256 free_netdev(netdev); 1257 1258 return 0; 1259 } 1260 1261 static int fjes_sw_init(struct fjes_adapter *adapter) 1262 { 1263 struct net_device *netdev = adapter->netdev; 1264 1265 netif_napi_add(netdev, &adapter->napi, fjes_poll, 64); 1266 1267 return 0; 1268 } 1269 1270 /* fjes_netdev_setup - netdevice initialization routine */ 1271 static void fjes_netdev_setup(struct net_device *netdev) 1272 { 1273 ether_setup(netdev); 1274 1275 netdev->watchdog_timeo = FJES_TX_RETRY_INTERVAL; 1276 netdev->netdev_ops = &fjes_netdev_ops; 1277 fjes_set_ethtool_ops(netdev); 1278 netdev->mtu = fjes_support_mtu[3]; 1279 netdev->flags |= IFF_BROADCAST; 1280 netdev->features |= NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_CTAG_FILTER; 1281 } 1282 1283 static void fjes_irq_watch_task(struct work_struct *work) 1284 { 1285 struct fjes_adapter *adapter = container_of(to_delayed_work(work), 1286 struct fjes_adapter, interrupt_watch_task); 1287 1288 local_irq_disable(); 1289 fjes_intr(adapter->hw.hw_res.irq, adapter); 1290 local_irq_enable(); 1291 1292 if (fjes_rxframe_search_exist(adapter, 0) >= 0) 1293 napi_schedule(&adapter->napi); 1294 1295 if (adapter->interrupt_watch_enable) { 1296 if (!delayed_work_pending(&adapter->interrupt_watch_task)) 1297 queue_delayed_work(adapter->control_wq, 1298 &adapter->interrupt_watch_task, 1299 FJES_IRQ_WATCH_DELAY); 1300 } 1301 } 1302 1303 static void fjes_watch_unshare_task(struct work_struct *work) 1304 { 1305 struct fjes_adapter *adapter = 1306 container_of(work, struct fjes_adapter, unshare_watch_task); 1307 1308 struct net_device *netdev = adapter->netdev; 1309 struct fjes_hw *hw = &adapter->hw; 1310 1311 int unshare_watch, unshare_reserve; 1312 int max_epid, my_epid, epidx; 1313 int stop_req, stop_req_done; 1314 ulong unshare_watch_bitmask; 1315 unsigned long flags; 1316 int wait_time = 0; 1317 int is_shared; 1318 int ret; 1319 1320 my_epid = hw->my_epid; 1321 max_epid = hw->max_epid; 1322 1323 unshare_watch_bitmask = adapter->unshare_watch_bitmask; 1324 adapter->unshare_watch_bitmask = 0; 1325 1326 while ((unshare_watch_bitmask || hw->txrx_stop_req_bit) && 1327 (wait_time < 3000)) { 1328 for (epidx = 0; epidx < hw->max_epid; epidx++) { 1329 if (epidx == hw->my_epid) 1330 continue; 1331 1332 is_shared = fjes_hw_epid_is_shared(hw->hw_info.share, 1333 epidx); 1334 1335 stop_req = test_bit(epidx, &hw->txrx_stop_req_bit); 1336 1337 stop_req_done = hw->ep_shm_info[epidx].rx.info->v1i.rx_status & 1338 FJES_RX_STOP_REQ_DONE; 1339 1340 unshare_watch = test_bit(epidx, &unshare_watch_bitmask); 1341 1342 unshare_reserve = test_bit(epidx, 1343 &hw->hw_info.buffer_unshare_reserve_bit); 1344 1345 if ((!stop_req || 1346 (is_shared && (!is_shared || !stop_req_done))) && 1347 (is_shared || !unshare_watch || !unshare_reserve)) 1348 continue; 1349 1350 mutex_lock(&hw->hw_info.lock); 1351 ret = fjes_hw_unregister_buff_addr(hw, epidx); 1352 switch (ret) { 1353 case 0: 1354 break; 1355 case -ENOMSG: 1356 case -EBUSY: 1357 default: 1358 if (!work_pending( 1359 &adapter->force_close_task)) { 1360 adapter->force_reset = true; 1361 schedule_work( 1362 &adapter->force_close_task); 1363 } 1364 break; 1365 } 1366 mutex_unlock(&hw->hw_info.lock); 1367 1368 spin_lock_irqsave(&hw->rx_status_lock, flags); 1369 fjes_hw_setup_epbuf(&hw->ep_shm_info[epidx].tx, 1370 netdev->dev_addr, netdev->mtu); 1371 spin_unlock_irqrestore(&hw->rx_status_lock, flags); 1372 1373 clear_bit(epidx, &hw->txrx_stop_req_bit); 1374 clear_bit(epidx, &unshare_watch_bitmask); 1375 clear_bit(epidx, 1376 &hw->hw_info.buffer_unshare_reserve_bit); 1377 } 1378 1379 msleep(100); 1380 wait_time += 100; 1381 } 1382 1383 if (hw->hw_info.buffer_unshare_reserve_bit) { 1384 for (epidx = 0; epidx < hw->max_epid; epidx++) { 1385 if (epidx == hw->my_epid) 1386 continue; 1387 1388 if (test_bit(epidx, 1389 &hw->hw_info.buffer_unshare_reserve_bit)) { 1390 mutex_lock(&hw->hw_info.lock); 1391 1392 ret = fjes_hw_unregister_buff_addr(hw, epidx); 1393 switch (ret) { 1394 case 0: 1395 break; 1396 case -ENOMSG: 1397 case -EBUSY: 1398 default: 1399 if (!work_pending( 1400 &adapter->force_close_task)) { 1401 adapter->force_reset = true; 1402 schedule_work( 1403 &adapter->force_close_task); 1404 } 1405 break; 1406 } 1407 mutex_unlock(&hw->hw_info.lock); 1408 1409 spin_lock_irqsave(&hw->rx_status_lock, flags); 1410 fjes_hw_setup_epbuf( 1411 &hw->ep_shm_info[epidx].tx, 1412 netdev->dev_addr, netdev->mtu); 1413 spin_unlock_irqrestore(&hw->rx_status_lock, 1414 flags); 1415 1416 clear_bit(epidx, &hw->txrx_stop_req_bit); 1417 clear_bit(epidx, &unshare_watch_bitmask); 1418 clear_bit(epidx, &hw->hw_info.buffer_unshare_reserve_bit); 1419 } 1420 1421 if (test_bit(epidx, &unshare_watch_bitmask)) { 1422 spin_lock_irqsave(&hw->rx_status_lock, flags); 1423 hw->ep_shm_info[epidx].tx.info->v1i.rx_status &= 1424 ~FJES_RX_STOP_REQ_DONE; 1425 spin_unlock_irqrestore(&hw->rx_status_lock, 1426 flags); 1427 } 1428 } 1429 } 1430 } 1431 1432 /* fjes_init_module - Driver Registration Routine */ 1433 static int __init fjes_init_module(void) 1434 { 1435 int result; 1436 1437 pr_info("%s - version %s - %s\n", 1438 fjes_driver_string, fjes_driver_version, fjes_copyright); 1439 1440 result = platform_driver_register(&fjes_driver); 1441 if (result < 0) 1442 return result; 1443 1444 result = acpi_bus_register_driver(&fjes_acpi_driver); 1445 if (result < 0) 1446 goto fail_acpi_driver; 1447 1448 return 0; 1449 1450 fail_acpi_driver: 1451 platform_driver_unregister(&fjes_driver); 1452 return result; 1453 } 1454 1455 module_init(fjes_init_module); 1456 1457 /* fjes_exit_module - Driver Exit Cleanup Routine */ 1458 static void __exit fjes_exit_module(void) 1459 { 1460 acpi_bus_unregister_driver(&fjes_acpi_driver); 1461 platform_driver_unregister(&fjes_driver); 1462 } 1463 1464 module_exit(fjes_exit_module); 1465